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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with onload and url 1

Status
Not open for further replies.

Igeeky1

MIS
Mar 17, 2000
8
0
0
US
While the script below works fine, I work with templates and therefore using the html <body> tag is not a good option at all? What other way do I need to be approaching this?

Thanks

Mark

<SCRIPT LANGUAGE="JavaScript">
function popUp(URL) {
day = new Date();
id = "page" + day.getTime();
id = window.open(URL, id, 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1');
}
</script>
</head>
<body onLoad="popUp('
 
First off... make sure you do your script tags in lower case... and use the following syntax (note: the language attribute is no longer used):
Code:
<script type="text/javascript">
...
</script>
That out of the way... you can replicate your code using the following technique:
Code:
<script type="text/javascript">
...
if (window.onload) {
  var oldFunction = window.onload; 
  window.onload = function() {
    oldFunction();
    popUp('[URL unfurl="true"]http://www.example.com');[/URL]
  }
} else {
  window.onload = function() {
    popUp('[URL unfurl="true"]http://www.example.com');[/URL]
  }
}
...
</script>
This solution will allow you to handle the case when there is existing code set to run when the page has loaded.

You should consider jQuery and Prototype - both are javascript frameworks that make these kinds of (and other) tasks very very very simple.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Thanks Jeff, I admit I'm not completely following the how and why here but it works great!

Mark



Mark
mferrel@kentdisplays.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top