Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script disables "Back" button; solution? 1

Status
Not open for further replies.

ganton1

Technical User
May 11, 2007
2
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>
 
Hi

First of all, using different pages is considered a bad practice. I would redesign it.

Try with [tt]replace()[/tt]. That will not leave the current page in the history.
Code:
<script type="text/javascript">
if (screen.width == 1024)
  parent.location.replace('./html/start1024.html');
</SCRIPT>

Feherke.
 
Thanks, Feherke. Although your modification fixed the issue, I did more reading on the Internet and found that the redirect process is not a good idea, as you suggested. My intent was not to advance search engine ratings, but rather to deliver an optimal page based on my viewer's resolution settings. I have now, however, redesigned the pages so that redirection is not necessary.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top