Firefox 后退按钮未按预期工作:显示 javascript 而不是 html
我正在使用 History.js 使我的 ajax 页面可添加书签并获得预期的后退/前进浏览器按钮体验。在 Safari 中,一切都很好,但在 Firefox 6 中,如果我离开网站,然后使用后退按钮返回,我会得到 javascript 而不是页面:
- 转到 mysite.com/user/1/post_board
- 单击帖子过滤器,地址更改为mysite.com/user/1/post_board?filter=one
- 在地址栏中输入 google.com
- 按后退按钮
- 我看到第 2 步加载的 javascript
发生了什么?我做错了什么?
这是代码:
// Bind to StateChange Event
History.Adapter.bind(window,'statechange',function(e)
{
var state = History.getState();
eval(state.data.function_rest + "("+JSON.stringify(state)+");");
History.log(state);
});
$('.message_filter').bind('click', function()
{
History.pushState({"function_rest":"restore_post_board_widget"}, document.title, this.href);
return false
});
function restore_post_board_widget(state)
{
$.getScript(state.url);
}
感谢您的帮助。
I am using History.js to make my ajax pages bookmarkable and to have the expected back/forward browser button experience. In Safari all works great but in Firefox 6 if I leave my site and then go back using hte back button I get the javascript instead of the page:
- go to mysite.com/user/1/post_board
- click on post filter, address changes to mysite.com/user/1/post_board?filter=one
- enter google.com in address bar
- push the back button
- I see the javascript loaded at step 2
What is going? What I am doing wrong?
Here is the code:
// Bind to StateChange Event
History.Adapter.bind(window,'statechange',function(e)
{
var state = History.getState();
eval(state.data.function_rest + "("+JSON.stringify(state)+");");
History.log(state);
});
$('.message_filter').bind('click', function()
{
History.pushState({"function_rest":"restore_post_board_widget"}, document.title, this.href);
return false
});
function restore_post_board_widget(state)
{
$.getScript(state.url);
}
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需添加:
window.onunload = function(){};
这就是我得到答案的地方:
在 Firefox 历史记录中回顾之后, JavaScript 不会运行
just add:
window.onunload = function(){};
this is where I got the answer:
After travelling back in Firefox history, JavaScript won't run