如果页面的 url 带有 '#' 且嵌入了 flash/swf,IE 标题将更改为

2024-03-11

问题是,如果 IE (6.0+) 嵌入了 Flash 内容,并且页面的 url 中某处有 #,那么当 Flash 内容加载时,或者如果用户与其交互,则标题窗口中,更改为散列后的内容。

e.g http://adobeflashwebsite.com/index.html#somediv http://adobeflashwebsite.com/index.html#somediv

然后,当用户单击 Flash 内容时,或者很多时候甚至在加载 Flash 内容时,页面标题会更改为 'somediv' 。

这种情况只发生在 IE 中。

下面是我面临的一个非常具体的案例:

以下是我面临问题的环境:

  1. Shinding 引擎显示类似 iGoogle 的页面
  2. Sammy.js
  3. 渲染 flash/swf 的小工具

这里的问题是,无论我尝试使用哪个插件嵌入 flash,我最终都会遇到以下问题

  1. 当 Flash 完全加载时,它会附加类似 #tab/xx 的内容,这实际上是 sammy 用于存储页面内最后的导航历史记录的字符串
  2. 当用户开始与 Flash 交互时,标题将被完全删除,只有 #tab/xx 保留为标题。
  3. 当一个小工具被刷新时,即使这样也会出现像#2这样的问题。

有人可以建议,问题可能是什么? 它很可能与 sammy.js 有关,因为 iGoogle 没有这个问题。


以下解决方法是(到目前为止)我最接近解决问题的唯一方法:

var isIE11OrGreater = !!(navigator.userAgent.match(/Trident/) && !navigator.userAgent.match(/MSIE/));
if (!isIE11OrGreater) {
    var originalTitle = document.title.split("#")[0];    
    document.attachEvent('onpropertychange', function (evt) {
       if(evt.propertyName === 'title' && document.title !== originalTitle) {
        setTimeout(function () {
           document.title = originalTitle;
        }, 1);
    }
});

}

//Incase the developer wants to change the title manually, instead of directly using     //document.title=newtitle, he will need to use changeTitle(newTitle)
    function changeTitle(newTitle)
    {
        originalTitle = newTitle;
        document.title = newtitle;
    }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如果页面的 url 带有 '#' 且嵌入了 flash/swf,IE 标题将更改为 的相关文章

随机推荐