开发者

Set document.title to default

Just a quickie..

开发者_运维问答

If I set on an alert document.title to "ALERT" per say. Then want to set it back afterwards is there an ezmode way to do this or will it be setting an ID on the link tags to set the title back to the ID. Note its an external script that is used on 20+ pages.


Your question is a bit unclear because it starts talking about links and such. But you do specifically mention document.title, so...

If you set document.title, there's no way to set it back to its previous value without your saving the previous value and then restoring it, e.g.:

// Setting the value originally, remember the previous value first:
document.previousTitle = document.title;
document.title = "Testing 1 2 3";

// Restoring the previous title:
document.title = document.previousTitle;
document.previousTitle = undefined;

(Ideally, instead of clearing the previousTitle with document.previousTitle = undefined;, we'd use delete document.previousTitle;, but sadly that breaks on IE because document isn't really a JavaScript object, it just behaves very much like one, mostly.)

You might think: Let's go find the title element in the head and use its original content to restore the title. (That's what I thought.) But no, setting document.title actually updates the content of the title element in the head, so that doesn't work. You have to save the original somewhere else.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜