WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-30-2003, 06:08 AM
WebProWorld New Member
 

Join Date: Sep 2003
Location: Linköping, Sweden
Posts: 11
nordic-design RepRank 0
Default Javascript relocate problems !!!

Hi

I culd really need some help with relocating my customars!
On my site i have a file (index.html) that checks the browser and relocate to (index_ie.html) or (index_ns.html) where I have my frameset.

I would like my custmars to be able to click the browsers back button once to go back to wherever they came from.

I have looked around on the net to find a solution but failed every time.
Can anyone please help me with my problem.
What code shuld I use and where shuld I place the code?
Im not very good at javascrip...

Thanx and hoping for your help.

Sissel Andersen*
My site:
http://www.nordic-design.co.uk[/b]
Reply With Quote
  #2 (permalink)  
Old 09-30-2003, 03:52 PM
WebProWorld Pro
 

Join Date: Aug 2003
Location: United Kingdom
Posts: 128
OSFan RepRank 0
Default

These type of redirects always "break" the back button. They cause the user a great distress if they just wanna keep clicking back without doing other things.

I can't think of any way you are going to manage this in javascript without breaking it, unless you have a message like "Enter Here" which when clicked actually invokes the script, rather on the onLoad. This way, clicking back would take them back to your Enter Here page, and another back out of your site.

If you have knowledge and access to a scripting language like ASP, PHP, PERL you can do this inside the script, and return a redirect http header, these do not break the back button, nor does the user notice anything which is going on.
Reply With Quote
  #3 (permalink)  
Old 09-30-2003, 05:40 PM
WebProWorld Pro
 

Join Date: Jul 2003
Location: New Jersey, U.S.
Posts: 293
jdiben RepRank 0
Default

Try the following code in the <HEAD> of your redirect page and put your current redirect code where indicated. When you get to the redirect page the code will check to see where you came from. If you came from within your website by clicking the backbutton it should "hit" the backbutton for you again and take you to the page in the history before the redirect page. If you came from outside your site the code should run the redirect.

I havent tried this code but it should work.

Code:
<SCRIPT LANGUAGE="JavaScript">
     var validreferrers=new Array()
     validreferrers[0]="http://www.yoursite.com"
     validreferrers[1]="http://yoursite.com"

     var passed=0;

     for (i=0;i<validreferrers.length;i++){
          if (document.referrer.indexOf(validreferrers[i])!=-1){
               passed=1;
               break;
          }
     }

     if (passed==1){
          history.go( -1 );
     }else{
          // Insert your redirect code here.
     }
</SCRIPT>
Joe
Reply With Quote
  #4 (permalink)  
Old 10-01-2003, 09:01 AM
WebProWorld New Member
 

Join Date: Sep 2003
Location: Linköping, Sweden
Posts: 11
nordic-design RepRank 0
Default Still not working

Thanx jdiben for the script but I still can't get it to work.
I don't know if I'm doing anything wrong???

I changed "yoursite" to my URL address and added my redirect code where "// Insert your redirect code here." is placed.

Nothing happens at all when I try it.
Am I doing something wrong?

Sissel Andersen*
Reply With Quote
  #5 (permalink)  
Old 10-01-2003, 09:34 AM
WebProWorld Pro
 

Join Date: Jul 2003
Location: New Jersey, U.S.
Posts: 293
jdiben RepRank 0
Default

Sorry Sissel,

I didnt realize document.referrer only works when following a link(using the back button or typing the address in the address bar wont work). I just did a search on google and from what I read the code I gave you is bad. I have to agree with OSFan that you will need to do this in a server side script. I apoligize for making you waste your time with my code, I should have tested it first.

Joe
Reply With Quote
  #6 (permalink)  
Old 10-01-2003, 06:55 PM
WebProWorld New Member
 

Join Date: Sep 2003
Location: Linköping, Sweden
Posts: 11
nordic-design RepRank 0
Default Thank you

Thank you both anyway for trying. It's difficult when you want to solve a problem and whatever you do fails.

I will have to see what I end up doing, if it's worth it or if I shuld just change the way I build up my site.
A lot of work *sigh*

Ah, well....
Thanx again!

Sissel Andersen*
Reply With Quote
  #7 (permalink)  
Old 11-09-2003, 05:13 PM
WebProWorld Member
 

Join Date: Aug 2003
Location: Canada
Posts: 30
AlexBel RepRank 0
Default Re: Thank you

Hi Sissel,
You can try this code:
Code:
<script language="JavaScript" type="text/javascript">
  var gop = (document.layers) ? "index_ns.html" : "index_ie.html";
  location.href=gop;
</script>
__________________
<-- AlexBel -->
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0