I've inserted a bit of JavaScript between the HEAD tags in my Web site's HTML so that when a viewer lands on the Home page, (s)he will be redirected to a given "start" page based on the browser's resolution settings, for example, a "start800.html" page or a "start1024.html" page. Now that the site is live on the server, I've discovered that, because a given "start" page is actually the second page in the process, the viewer will get stuck in a loop if trying to use the browser's "Back" button; (s)he will always end up at the redirected (second) page, which makes sense. This has the same effect as disabling the browser's "Back" button. I don't want to do that to my viewers. How can I fix this? One example line of the script looks like this: <SCRIPT LANGUAGE="javascript"> if (screen.width == 1024) {parent.location.href='./html/start1024.html'} </SCRIPT>
I can't find anything related on that page. Please, could you tell us which article are you talking about ?
Something like this maybe? Im not quite sure if this would work exactly the way you want though... Set a cookie on the entrypage document.cookie="Iusedmybackbutton"; In all other pages inside <head> if((document.cookie!= "")&&(document.cookie.indexOf("Iusedmybackbutton")!=-1 )) window.open("somepage.html");
Alternatively, you could cut out all the faff and go fixed width or fluid layout - you're not going to do your search rankings any favours redirecting people around like that.
Thanks for the replies, everyone. Although I was trying to set up optimum pages for a given viewer's browser, and not trying to play tricks with search engine rankings, I did further reading on the Web about how the engines handle this sort of thing, and I now think Dio's advice is best. I've converted the pages to 1024 fixed width for now. That may make a few viewers do some scrolling for less important content, but I still tried to keep the most important part of the page at 775 pixels wide or less. I may design a more fluid layout later.
Im not sure about javasript that can detect if user press back button, but the is code that can detect if the user try to close window or browse other page. You can try this: window.onbeforeunload and integrate with your script.