如果页面的url包含’#’,则IE标题会更改为,并且其中嵌入了flash / swf

问题是,如果IE(6.0+)中嵌入了Flash内容,并且页面的url中有一个#where,那么当加载flash内容时,或者如果用户与之交互,则标题为窗口,更改哈希后放置的内容。

例如http://adobeflashwebsite.com/index.html#somediv

然后页面标题变为’somediv’,用户点击Flash内容的时刻,或者甚至闪存内容加载的那一刻。

这只发生在IE中。

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

以下是我面临的问题:

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

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

  1. 当flash完全加载时,它会附加类似#tab / xx的内容,它实际上是sammy用来存储页面中最后一个导航历史的字符串
  2. 当用户开始与闪存进行交互时,标题将被完全删除,并且只有#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; } 

这是IE错误:

如果你使用sammy的title方法,你可以延迟执行一点,使其在IE上运行。

 setTimeout(function() { context.title('Some title'); }, 1000); 

这不会真的解决它,但我注意到有点延迟有助于IE。

我对sammy.js并不熟悉,但是:

1)Flash对象以某种方式’夺取’title属性的所有权。

要么

2)sammy.js正在清除HTML失去焦点的标题值,也就是Flash获得它(不太喜欢,也不知道为什么有人这样做)

如果1) – >在Flash对象本身中定义title属性(不是Flash用户,如果可以轻松完成则不知道)

如果2) – > javascript正在转储连接到title属性的变量字符串值?

建议:

将flash对象包含在新的

元素中,分配

一个.click()事件处理程序,该处理程序更改文档的title属性。 试试这个:

 $('title').text('YourTitleHere'); 

我参加派对有点晚了,但我更喜欢这种做法:

 var originalTitle = document.title; copyLinkClipboard = new ZeroClipboard(document.getElementById('copy-link-btn')); copyLinkClipboard.on( 'ready', function () { copyLinkClipboard.on( 'aftercopy', function (event) { event.target.blur(); console.log('Successfully copied link to your clipboard!'); document.title = originalTitle; // sets the title back on successful copy }); }); document.title = originalTitle; // sets title back when it changes on instantiation 

这特别是在ZeroClipboard更改它的两个事件中更改标题,而不是在document.onpropertychange事件上注册侦听器。

 //some changes if (browser.ie < 10) { document.attachEvent('onpropertychange', function(evt) { if (evt.propertyName === 'title' && document.title) { setTimeout(function() { var b=document.title.indexOf('#'); if(b!==-1){ document.title = document.title.slice(0,b); } }, 1); } }); }