Javascript 后退按钮 - 停止后退按钮的初始加载工作
我使用 JavaScript 后退按钮链接和前进按钮链接来控制模式/灯箱窗口内的用户历史记录。
我面临的挑战是,当模式窗口启动时,“后退”和“前进”按钮可供用户单击,如果在窗口打开时单击初始 JavaScript 后退按钮,它实际上会关闭模式窗口,因为 JavaScript 历史记录将用户带回到打开模式窗口之前的页面。
因此,本质上,我试图禁用“后退”按钮来处理模态/灯箱的初始负载。
这可能吗?这是正在发生的事情的演示...... http://www.apus.edu/_test/evan/modal/start。嗯
<a href="javascript:history.go(-1)">Back Button</a>
<a href="javascript:history.go(1)">Foward Button</a>
I'm using a javascript back button link and forward button link to control the user's history inside a modal/lightbox window.
The challenge I have is when the modal window is launched, and the "back" and "forward" buttons are present for the user to click, if the initial javascript back button is clicked when the window opens, it actually closes the modal window, because the javascript history is taking the user back to the page PRIOR to the opening of modal window.
So, in essence, I'm trying to disable the "back" button from working on the initial load of the modal/light box.
Is this possible? Here's a demo of what is happening...
http://www.apus.edu/_test/evan/modal/start.htm
<a href="javascript:history.go(-1)">Back Button</a>
<a href="javascript:history.go(1)">Foward Button</a>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定我是否理解您在使用模态窗口做什么,但我想到的第一件事是编写一个函数,并将 History.go(-1) 包装在条件
标记中
和 为了不让这个答案在没有提及 jQuery 的情况下完成:查看“jQuery BBQ:后退按钮和查询库”
更新:
好的,我们有什么这里是history.go在跨浏览器的iframe中的不一致行为。 Firefox3 似乎完全符合您的要求,而 Chromium 则不然。您可以做的是为您的“后退”链接提供一个 id
然后,在加载 iframe 内容后,您可以获取该链接:
或(使用 jQuery ;)
或执行您喜欢的任何其他操作。
I'm not exactly sure if I understand what you are doing with modal windows, but the first thing that pops to my mind is to write a function, and wrap the history.go(-1) in a conditional
and in your markup
Just to not let this answer finish without any mention of jQuery: check out "jQuery BBQ: Back Button & Query Library"
Update:
Okay, so what we have here is an inconsistent behavior of history.go in iframes across browsers. Firefox3 seems to do exactly what you want, Chromium doesn't. What you could do is to provide an id to your "back"-link
Then, after your iframe-content is loaded, you grab the link:
or (using jQuery ;)
or do whatever else you like with it.
尝试
history.pushState(null, '', '#stay');
*据我所知,这需要支持 HTML5 的浏览器。
Try
history.pushState(null, '', '#stay');
*As far as I know this requires HTML5 capable browser.