Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Friday, December 12, 2008

Javascript to close the current window

"<script language='javascript'>window.open('','_parent','');window.close();</script>"

Javascript Form Submit Using POST action Into a new Window

<form> element of html have several attributes for controlling submission

method : get or post
action : the url for the post back action
target : the target for the post back action, _blank, _parent, _self, _top, name of a window
name : name of the form

In this topic of using javascript to change POST action of a form so that it post into a new Window, action and target is the most important attribute here.

you can use javascript function window.open(url, name, param)
e.g. window.open(test.html,'','scrollbars=no,menubar=no,height=600,width=800,resizable=yes,toolbar=no,status=no');

to post into another window, we will set the action to the url of the new window and target is the name of the new window.
e.g.

function PostToNewWindow()
{
    form.action = 'newForm.asp?action=submit&param=new'; //any valid url and query string
    form.target = 'NewPopupForm'; // name of the new form
    window.open('', 'NewPopupForm', 'height=50, width=50, resizable = no, toolbar=no, status=no');
    form.submit;

}

Wednesday, December 10, 2008

Trim a string in JavaScript using replace function and regular expression

from this article http://www.nicknettleton.com/zine/javascript/trim-a-string-in-javascript

var trimmed = str.replace(/^\s+|\s+$/g, '') ;