简体   繁体   中英

Can't go back after javascript redirect

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();

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM