Forum Moderators: travelin cat

Message Too Old, No Replies

Javascript Redirect Problems

         

tsmid

3:11 pm on Feb 11, 2004 (gmt 0)

10+ Year Member



I have the following script in the header of my home page in order to skip automatically to an anchor 4sec after the page has loaded:

<SCRIPT Language="Javascript" type="text/javascript">
<!--
var mac=-1;
var anchor='';
if (navigator.userAgent) {mac=navigator.userAgent.search(/Mac/);}

function loaded(){
if (mac!=-1) {anchor='home';} else {anchor='#home';}
if (! window.location.hash) {window.location.hash=anchor;}
setTimeout('enter()',4000);
}

function enter(){
if (window.location.hash==anchor) {
if (mac!=-1) {anchor='enter';} else {anchor='#enter';}
window.location.hash=anchor;
}
}

//-->
</SCRIPT>

The function 'loaded()' is called through an onLoad event handler in the BODY tag.
The separate scripting for Macs was necessary because I found out that here the #-sign is internally added to the anchor name (both on IE5 and Safari) and otherwise would therefore appear twice.
However, what happens with the above script is that the function loaded() changes the window location to #home but nothing more (i.e. it either fails to execute the setTimeout() command or the function 'enter()').

On a PC this works perfectly with all browsers, but as mentioned, on Macs (I tested this in an Internet Cafe on an iMac) it fails with IE5.0, IE5.2 as well as Safari.

Any suggestions?

tsmid

9:54 pm on Feb 11, 2004 (gmt 0)

10+ Year Member



I found out in the meanwhile that the problem is presumably that the Mac cannot read the value of the object 'window.location.hash' (the same problem exists with the Opera browser on a PC).
I programmed around this now by using

function loaded(){
if (mac!=-1) {anchor='home';} else {anchor='#home';}
if (window.location.href.search(/#/)==-1) {window.location.hash=anchor; home=1;}
setTimeout('enter()',4000);
}

function enter(){
if (home==1) {
if (mac!=-1) {anchor='enter';} else {anchor='#enter';}
window.location.hash=anchor;
}
}

At least the redirect works now although it still does not recognize the # in the referrer (on Opera/PC) but this is of minor importance.