[英]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. 我当前的方法是
location.href='/this/page/'
尽管当我单击浏览器中的“后退”按钮时,它确实会后退,但会持续约5毫秒(至少看起来是这样)并返回到显示为刷新。 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
. 编辑:如果重要,我在
switch
。
EDIT: Here is the html/javascript I use to switch pages. 编辑:这是我用来切换页面的html / javascript。 This code is only on my splash page.
此代码仅在我的初始页面上。
HTML: HTML:
<select id="ds">
<option>>-- Select --<</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: 使用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. 您应该在重定向的目标页面上创建一个cookie,并且如果该cookie不存在,则仅在启动页面上执行
location.href
代码。 That way, when the user hits back, they won't be immediately redirected. 这样,当用户回击时,不会立即将其重定向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.