1

I currently have a function running on my page to change the page depending on what is selected on the splash page.

My current method is location.href='/this/page/' though when I click the back button in browser, it does go back but for roughly 5ms (at least what it looks like) and returns back to the page acting like a refresh. No matter how many times I click back, it doesn't go back to my splash page.

First time I click back, it does what I stated above, and the second click would go to what was before to splash page.

EDIT: If it matters, I have these in a switch.

EDIT: Here is the html/javascript I use to switch pages. This code is only on my splash page.

HTML:

<select id="ds">
    <option>&gt;-- Select --&lt;</option>
    <option value="1">Blue Sky Travel</option>
    <option value="2">Paterson's Curse</option>
    <option value="3">Eugowra Progress Society</option>
    <option value="4">Eugowra Bushranger County</option>
</select>

Javascript:

$('select#ds').change(function(){
    var i = $(this).val();
    switch(i) {
        case "1":
            location.href='/bst/'
            break;
        case "2":
            location.href='/pc/'
            break;
        case "3":
            location.href='/eps/'
            break;
        case "4":
            location.href='/w8/'
            break;
        default:
    }
}).change();
Spedwards
  • 4,167
  • 16
  • 49
  • 106
  • The problem you've described cannot be reproduced with your explanation. You're missing important details, try to post a [SSCCE](http://www.sscce.org/). – Fabrício Matté Apr 02 '14 at 03:51
  • How many pages are involved and what are their url's? Does the splash page have a dedicated url or is it loaded via, say AJAX? – mellamokb Apr 02 '14 at 03:51
  • @mellamokb Splash page has a dedicated url. I am using this method for 8 different pages and they all do the same thing. For four of them, they are just `location.href='/pageX/';` and the other four are the same but in a directory. – Spedwards Apr 02 '14 at 03:53
  • @FabrícioMatté If I knew what was causing it, I could give you important details, but in this case, I cannot. – Spedwards Apr 02 '14 at 03:54
  • @Spedwards: Can you provide the JavaScript code you are using to switch pages? It sort of depends on the ordering of events in the browser to understand the behavior you are seeing. – mellamokb Apr 02 '14 at 03:56
  • @mellamokb I've edited my question to provide the code. – Spedwards Apr 02 '14 at 04:00
  • 1
    Seems like you've hit a Chrome bug. This [live test case](http://jsfiddle.net/G2Pct/show/) of your code reproduces your described issue in Chrome, but not Firefox/IE. – Fabrício Matté Apr 02 '14 at 04:07
  • You could try utilizing pushState, as suggested here http://stackoverflow.com/a/5401748/481422 – Zlatin Zlatev Apr 02 '14 at 04:07

1 Answers1

1

You should create a cookie on the landing page of the redirect, and only execute the location.href code on the splash page if the cookie does not exist. That way, when the user hits back, they won't be immediately redirected.

Alex W
  • 37,233
  • 13
  • 109
  • 109
  • I have never worked with cookies so I don't exactly want to use them. What I would rather is knowing why it does what it does so I can work around it. – Spedwards Apr 02 '14 at 04:02
  • @Spedwards Your `location.href` code is being executed as soon as you load the page. You can work around it by putting that redirect code in a conditional statement. – Alex W Apr 02 '14 at 04:09