Some JavaScript Tips and Tricks


Obtaining screen resolution.



The following code used:


<script>
 if(screen)
   {document.writeln("Your screen resolution is: "+screen.width+" x "+screen.height);
   }
</script>

Creating JavaScript tag in on-the-fly documents.


If you are creating an on-the-fly document from JavaScript you just can't place something like document.writeln("<SCRIPT>") The browser will screw up on this tag. So to avoid this problem you can use the following code instead
document.writeln("<SC"+"RIPT>");

Page which can be opened only as part of frameset and page which always jump out from frames.

Place this code somewhere in the top of your document. So if somebody comes to this page directly around frameset, frameset.html will be loaded.

<SCRIPT>
if(window==top.window) 
  {top.window.location='frameset.html'} 
</SCRIPT>

You will find a more complicated but more flexible Script example here.

Suppose your page will be linked as a part of another site frameset? Want to "jump out"? Place this code at the top of your document:

<SCRIPT>
if(window!=top.window)
{top.window.location=""+window.location}
</SCRIPT>

Open new maximized window.

Do not be afraid to open your browser window larger than the screen, its size will be limited with sceen resolution. The only problem is that older browsers won't place new window at top left corner. But, MIE4 and NN4 will do this.

<script>
window.open("","windowName","width=2000,height=2000,screenX=0,screenY=0");
</script>

Obtaining browser info


Keep Child Window always on top.

Place this code inside <HEAD></HEAD> of the child window:

<SCRIPT>
function ontop() 
{self.focus(); setTimeout("turnback()",200);}
ontop();
</SCRIPT>

I'm looking for a javascript that will preload images in the background.

You can do it without JavaScript. You can create frameset with hidden (zero size, non resizable and borderless) frame. All you need is to place all your images in this HTML document. So all images will be loaded in this frame and cached.

Disable right click

Simple like an egg.. You will find it here. here