开发者

Change IE title from bookmarklet

开发者 https://www.devze.com 2023-01-26 04:19 出处:网络
I am creating a JavaScript bookmarklet that dynamically update开发者_开发技巧s the title bar, but it doesn\'t display the changes in IE (I\'ve tried IE7 and IE8). Here\'s a simplified example that dem

I am creating a JavaScript bookmarklet that dynamically update开发者_开发技巧s the title bar, but it doesn't display the changes in IE (I've tried IE7 and IE8). Here's a simplified example that demonstrates my issue:

javascript:document.title='new title';alert(document.title);

Notice that the the value is updated in the alert, but not on the title bar or tab. It is working fine for me in Chrome.


It's a bug in IE. It's possible to work around it by changing the URL's fragment identifier ("hash"), which may or may not be feasible for your purpose:

javascript:document.title='foobar';location.replace('#'+new Date().getTime())

new Date().getTime() is used to get a unique number that is unlikely to be used as a name or ID anywhere in the page (so that the page does not actually scroll).


From my experience most browsers will update the new TITLE in the browser window or tab.

However it seems with IE browsers they only set it one time and then that's it - no further updates. If thats true (would love to see a solution as well) then there is no way around it.

0

精彩评论

暂无评论...
验证码 换一张
取 消