William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

JavaScript and Browser Objects Quick Reference and some tips.

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.

  1. 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.
  2. self, parent window
    use self.opener.document or window.opener.document to refer current window’s parent window.
    e.g., if using <frameset>, 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';}

    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.value

    where “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

  3. How do I close the main window after it’s opened a new window?

    To change the opener’s bgcolor :

  4. 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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: