JavaScript and Browser Objects Quick Reference and some tips.
Blogs20112011-05-31
Here is a very useful JavaScript archieve:
JavaScript and Browser Objects Quick Reference
Donât say jQuery is enough, not use pure JavaScript anymore. Actually jQuery Object needs DOMâs assistant: JavaScriptâs document, window, regular expressions objects are used everywhere. The above PDF can provide great help of JavaScript Objectsâ quick reference.
Besides above, I summary some tips about JavaScripts I used in my rountine work.
- JavaScript Window Object and Document Object. The window object is a top level client side object. There is nothing above the window object. the document object is an object of the window object. So window.document is correct, and document.window is not.
-
self, parent window use self.opener.document or window.opener.document to refer current windowâs parent window. e.g., if using , it is always a challenge to communicate between different frames under the frameset. The following is my way to redirect window:
if(! ((isset($_SESSION['userid']) && $_SESSION['userid'])) ) { echo "if(self.opener){self.opener.location.href='login.php';} else{window.parent.location.href='login.php';}"; exit; }Without JavaScript âparentâ or âselfâ objects support, the communication will become difficult.
Another example is by using the opener property of the window object. A form in the main window can be referenced the same way. e.g.:
text = window.opener.document.formname.formfield.valuewhere âformnameâ is the name youâve given to your form using the name attribute and formfield is the name of the form field youâre wanting to reference
-
How do I close the main window after itâs opened a new window? window.opener.close()
To change the openerâs bgcolor : window.opener.document.bgcolor=âredâ
-
calendar.js bug. I used a old calendar.js file, which works fine in FF and Chrome, but not in IE. The reason is the event is not only âwindowâ object, but also âscriptâ object: window.event can be identified by IE, but event not.
tempX = event.clientX + document.body.scrollLeft // not work. tempX = window.event.clientX + document.body.scrollLeft // work.So use window.event instead of event make codes more strong to be compatible with I.E. versions.
