Script prevents use of "Back" button; need solution

Discussion in 'JavaScript' started by ganton1, May 11, 2007.

  1. #1
    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>
     
    ganton1, May 11, 2007 IP
  2. gibex

    gibex Active Member

    Messages:
    1,060
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    95
    #2
    gibex, May 14, 2007 IP
  3. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #3
    I can't find anything related on that page. Please, could you tell us which article are you talking about ?
     
    ajsa52, May 14, 2007 IP
  4. wing

    wing Active Member

    Messages:
    210
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    58
    #4
    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");
     
    wing, May 15, 2007 IP
  5. Dio

    Dio Well-Known Member

    Messages:
    725
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    120
    #5
    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.
     
    Dio, May 15, 2007 IP
  6. ganton1

    ganton1 Guest

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.
     
    ganton1, May 22, 2007 IP
  7. tinkerbox

    tinkerbox Peon

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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.
     
    tinkerbox, May 24, 2007 IP