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.
yingkitAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
cheekycjConnect With a Mentor Commented:
DC,
your script does the redirecting to index.html but how will he know that the person wanted download.html loaded? I am assuming that is not the main page and will not be loaded every time someone arrives at index.html.

You need to pass a variable via the URL to and then check if download.html is what they wanted.

<script>

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

</script>

then in your right frame put the following code:

<script>
if (urlvar.search('dnld') != -1) {
       window.framename.href="download.html"
}
</script>

or alternatively use for your right frame put the following code:

<script>
var srchstring = window.location.search.substring(1);
</script>

this will set the value of:
srchstring = "&loc=dnld"
now you can parse the srchstring to check which page they wanted and redirect them accordingly.

CJ
0
 
deepchandaCommented:
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
0
 
cheekycjCommented:
for more indepth look into url vars check out:
http://developer.iplanet.com/viewsource/goodman_url_pass/goodman_url_pass.html

CJ
0
 
yingkitAuthor Commented:
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.
0
 
cheekycjCommented:
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
0
All Courses

From novice to tech pro — start learning today.