PDA

View Full Version : Forward User to Page Based on URL...


sabotage1945
12-13-2002, 10:57 AM
Hello there,

This is my first post on this site. I've been going crazy thinking of ways to allow my website visitors go to specific pages, based on what they have typed on their URL statement.

For example:

I have registered the following URLs ALL pointing to the same IP/web server. Lets say the names are:

www.testing.com
www.testing.com.au
www.testing.co.jp

if a user comes from .com, I would like it to go to my north america page, and if they come from .con.au, I would like them to go to my English-Australian page, same goes with the Japanese domain name.

So far I have the following script in my INDEX.HTML file:

<SCRIPT>

var obj = window.top.location;
if (obj.href.indexOf("test.com.au")==(-1)) {
obj.href = 'jp/welcome_jp.htm';
} else {
obj.href = 'en/welcome_auen.htm';
}
</SCRIPT>

However, if a user comes from test.com the script goes to a 404-page. But it would be nice if it could go to welcome_usen.htm as an example.

Thank you for your help and recommendations.

Kindest regards,
Sab

ACJavascript
12-13-2002, 10:30 PM
why dont you try somthing like this. Using document.refferer

________--
<script language="javascript">

function Where(){

if(document.refferer == "http://www.testing.com"){
location.href="american_page.html"
}else if(document.refferer == "http://www.testing.com.au"){
location.href="other_page.html"
}else if(document.refferer == "http://www.testing.com.jp"){
location.href="other_page2.html"
}else{
location.href="Welcome_user.html"
}

}
window.onload=Where

</script>

the last else{

is the page that is shown if the requirments above are not met..

Happy Scripting :D

sabotage1945
12-14-2002, 11:25 AM
THANKS FOR THAT!!! :thumbsup:

It has worked wonderfully! As a new user to JavaScript, I did not know of this function.

A million thanks!
Sab

krycek
12-14-2002, 11:53 AM
that's odd... if you used ACJavaScript's code exactly as he/she wrote it, it should not work! :confused:

Where ACJavaScript put "document.refferer" it should read "document.referrer" - a simple spelling mistake but it would prevent the script from working.

::] krycek [::

ACJavascript
12-14-2002, 04:15 PM
LOL:D You right ,,,, I wonder why it worked.. Mabye Sabot saw that and changed it lol.....

sabotage1945
12-18-2002, 05:16 AM
Thanks for pointing that out! I didn't even pick up on the sp error. Curiously it works just fine?? I double checked.

Don't ask me why that is... I'm just a new-B :o

Anyhow, I'll change what I have in my INDEX.HTML to the corrected spelling as I'm sure it may prevent errors occurring in some browsers.

Cheers,
Sabo