Link to home
Start Free TrialLog in
Avatar of yingkit
yingkit

asked on

Detect and redirect

Hi,
How can I do the following?
If my visitor tries to acesss a particular HTML files of my homepage DIRECTLY, say "download.html", my homepage will then automatically redirect him back to "index.html" with "download.html" being opened in the "RIGHT" frame.

Thanks in advance.
PS.  Javascript answers preferred.
Avatar of deepchanda
deepchanda

inlcude the following script at the beginning of the page download.html b4 the <body> starts

<script>

urlvar = window.location.href;
if (urlvar.search('download.html') != -1) {
       window.location.href="index.html"
}

</script>

I understand that index.html is a page with all the frameset definitions in which case you can load the download.html on the right frame.

DC
ASKER CERTIFIED SOLUTION
Avatar of cheekycj
cheekycj
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yingkit

ASKER

Hi CJ,
Can you post the some sample html files here, or tell me which file(s) should the scripts be placed at?
Moreover, whenever download.html with the following code is loaded, it causes my netscape4 to split frames continuously:
<script>
urlvar = window.location.href;
if (urlvar.search('download.html') != -1) {
window.location.href="index.html"
}
</script>
Thanks.
oops small problem in the code:
need to use:
<script>
urlvar = window.parent.location.href;
//or urlvar = window.parent.location.pathname;
if ((urlvar.search('download.html')) != -1) {
      alert("redirecting");
      window.location="index.html";
}      
</script>

if you don't use parent... it doesn't look at the top window but the current frames location so you always found the download.html if it was loaded in that frame.

Sorry,
CJ