Safari后退按钮问题 [英] The Safari Back Button Problem

查看:138
本文介绍了Safari后退按钮问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为当地社区大学做一些小编程和网络工作。这项工作包括维护一个非常庞大且灵魂破坏的网站,其中包括VBScript,javascript,Dreamweaver产生的混乱和一系列附加组件,各种各样的conmen已经说服他们多年来购买。

I do some minor programming and web work for a local community college. Work that includes maintaining a very large and soul destroying website that consists of a hodge podge of VBScript, javascript, Dreamweaver generated cruft and a collection of add-ons that various conmen have convinced them to buy over the years.

几天前我接到一个电话网站正在锁定使用Safari的人!好的,第一步下载Safari(v3.1.2),第二步冲浪到网站。一切似乎都运行良好。

A few days ago I got a call "The website is locking up for people using Safari!" Okay, step one download Safari(v3.1.2), step two surf to the site. Everything appears to work fine.

长话短说我终于解决了问题,它与Safari的后退按钮有关。该网站使用了一个花式裤子javascript菜单,可以在我尝试过的每个浏览器中使用,包括Safari,这是第一次。但是在Safari中,如果你按照页面上的链接然后点击后退按钮,菜单就不再有效了。

Long story short I finally isolated the problem and it relates to Safari's back button. The website uses a fancy-pants javascript menu that works in every browser I've tried including Safari, the first time around. But in Safari if you follow a link off the page and then hit the back button the menu no longer works.

我做了一个简化的网页来说明原理。 / p>

I made a pared down webpage to illustrate the principle.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><title>Safari Back Button Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body onload="alert('Hello');">
<a href="http://www.codinghorror.com">Coding Horror</a>
</body>
</html>

加载页面,您会看到警告框。然后按照页面上的链接点击后退按钮。在IE和Firefox中你会再次看到警告框,在Safari中你不会。

Load the page and you see the alert box. Then follow the link off the page and hit the back button. In IE and Firefox you see the alert box again, in Safari you do not.

经过一次激烈的谷歌搜索后,我发现其他人有类似的问题,但没有真正令人满意的答案。所以我的问题是,在用户点击后退按钮之后,如何在其他浏览器中使我的页面在Safari中以相同的方式工作?

After a vigorous googling I've discovered others with similar problems but no really satisfactory answers. So my question is how can I make my pages work the same way in Safari after the user hits the back button as they do in other browsers?

如果这是一个愚蠢的问题请保持温和,javascript对我来说有点新鲜。

If this is a stupid question please be gentle, javascript is somewhat new to me.

推荐答案

Stefan的iframe解决方案有效,但如果这不够优雅,我找到以下JavaScript也解决了它:

Stefan's iframe solution works, but if that's not elegant enough, I find the following JavaScript also solves it:

window.onunload = function(){};

也就是说,如果您的菜单是JavaScript,那么您也可能更喜欢用JavaScript解决这个问题。

That is, if your menu is JavaScript, then you might prefer to solve this issue with JavaScript too.

卸载事件处理程序定义的想法来自这篇Firefox 1.5文章: https://developer.mozilla.org/en/Using_Firefox_1.5_caching

The unload event handler definition idea came from this Firefox 1.5 article: https://developer.mozilla.org/en/Using_Firefox_1.5_caching.

这篇关于Safari后退按钮问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆