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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.