简体   繁体   English

使用JavaScript重定向HTML页面

[英]Redirecting html page with javascript

I have a combo-box which redirects a user to a specific page. 我有一个组合框,可将用户重定向到特定页面。 To redirect, if I use 重定向,如果我使用

window.location.href = ...

when they hit back, it automatically redirects again. 当他们回击时,它会自动再次重定向。 And if I use 如果我用

window.location.replace (...)

they can't go back, because the history gets replaced with the new page. 他们无法返回,因为历史记录已被新页面替换。

I would have thought it's a fairly common scenario, so just wanted to ask if anyone knows a trick I'm missing? 我本以为这是一个相当普遍的情况,所以只想问问是否有人知道我所缺少的把戏?

Thanks 谢谢

just check position of your syntax. 只需检查语法的位置即可。
put it inside some function or event. 将其放在某些函数或事件中。
use below syntax : 使用以下语法:
window.location = "your_url"; window.location =“ your_url”;

Ok, finally figured it out. 好的,终于明白了。 Turns out the jquery MultiSelect I'm using seems to preserve it's value so when I go 'back' into the browse, the MultiSelect kicks off an event as though it's been selected, which kicks off the redirect :( Fixed now by clearing the selected item and then redirecting. 原来我正在使用的jQuery MultiSelect似乎保留了它的值,因此当我“返回”浏览时,MultiSelect就像选择了它一样启动了一个事件,这启动了重定向:(现在通过清除选定内容来解决项目,然后重定向。

尝试使用select的onchange事件,以便在用户更新值之前不会发生重定向。

  <script language='javascript'>window.location='index.php'</script>

有用...

Try this way 试试这个

before u do window.location.url do like.. 在你做window.location.url之前喜欢..

if (!window.flag) window.location.url
window.flag=true;

So after u instructed for redict, ur resetting the flag.. so when u hit back buttion on the new page.. it goes to the old page.. but doesnt rediect 因此,在您指示撤回命令之后,我们将标记重置。.因此,当您在新页面上点击按钮时,它会转到旧页面..但不会重新显示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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