Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I make a link run when page loads?

Status
Not open for further replies.

neutec

Technical User
Apr 26, 2003
343
Hello everyone,
I would like to link to run when someone opens my home page. The link is to open a DHTML window. Whats the best way to open this window?
 
When you just want another window to open when your page loads, that can be done with JavaScript. Remember however, that opening new windows automatically is not appreciated by a lot of users. Furthermore, popup killers can block JavaScript opening new windows and some users have JavaScript turned off in their browser settings. However, here's the script for opening a new window:

<script language=&quot;JavaScript>
function openNewWindow ()
{
var myWindow;

myWindow = window.open (&quot;urlOfNewWindow&quot;, &quot;titleOfNewWindow&quot;, left=100, top=100, width=400, height=400);
}
</script>

This will open a new window at postion 100, 100 with a size of 400 by 400 pixels. Replace &quot;urlOfNewWindow&quot; with your own url and &quot;titleOfNewWindow&quot; with your own title. Watch out with special characters in the title. A lot of them are not allowed. Best thing is to use just ONE word (no spaces even).

Put this script just before the </head> tag.
The <body> tag should look like this:

<body onLoad=&quot;openNewWindow()&quot;>
 
thanks for your help, I have one more question. My <body> look like this

<body leftmargin=&quot;0&quot; topmargin=&quot;0&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; onLoad=&quot;MM_preloadImages('images/btn_main_dn.gif','images/btn_about_dn.gif','images/btn_products_dn.gif','images/btn_services_dn.gif','images/btn_support_dn.gif','images/btn_contactus_dn.gif','images/btn_order_dn.gif')&quot;>

How would I change it to work with the java script?
 
Change

onLoad=&quot;MM_preloadImages ...etc

into

onLoad=&quot;openNewWindow ();MM_preloadImages ...etc

In other words, just put the name of the openNewWindow function in front of the other code (MM_preloadImages etc)
Don't forget the semicolon after openNewWindow ()! It's important.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top