...

View Full Version : Delay execution of 2nd half...



Mr Twirly Cane
10-13-2003, 05:02 AM
Hi!

I can muddle through JS but I'm no pro...

Below is frames() a dynamic frameset script for visitors hitting my internal pages out-of-frames. Works just fine but writes the frameset too quick, visitors can't back-out. I simply want to show a message "You are out of frames buddy" and give a polite 2 second pause before writing the frameset.

So I'm calling detect() from the body tag to doc.write a message and pause before calling "frames()". My message is getting onscreen but function frames() won't function! If I delete my document.write message then it all works just fine?!? What on Earth am I doing wrong?

Many thanx in advance...

<script language="JavaScript">
<!--
function detect() {
if (top.frames.length==0) {
document.write('<font size="2" color="crimson" face="verdana,helvetica,sans-serif"><b>out of frames</b></font><br>');
document.write('<font size="1" color="black" face="verdana,helvetica,sans-serif">loading frameset...</font>');
timer=setTimeout('frames()',2000) }
}

function frames() {
framesetpage="awnings-frameset.html";
thispage=window.location.href;
if (thispage.indexOf('://')<0) {thispage="://"+thispage;};
prefix=thispage.substring(0,thispage.lastIndexOf('://'));
suffix=thispage.substring(thispage.lastIndexOf('://')+3,thispage.length);
// alert('the subpage is:['+prefix+']['+suffix+']');
if (parent.location.href==window.location.href) {parent.location.href=framesetpage+"?"+prefix+"&&&"+suffix};
}
// -->
</script>

Roy Sinclair
10-13-2003, 07:13 PM
If you're calling detect from the body tag that means you must be using the onload event. That also means that document.write replaces the current document with the new document written by your document.write statements so the delayed function never executes. You need to try putting the call to detect as the last thing before the </body> tag instead.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum