2010-06-24 170 views
1

只是一个快速的..将document.title设置为默认

如果我设置一个警报document.title每个说“警报”。 然后想要将它设置回来之后有一个ezmode方式来做到这一点,或者它将在链接标签上设置一个ID来将标题设置回ID。请注意,它是一个在20多页上使用的外部脚本。

回答

4

你的问题有点不清楚,因为它开始讨论链接等。但是,你特别提到document.title,所以......

如果设置document.title,有没有办法将它恢复到原来的值,而你保存先前的值,然后还原它,例如:

// 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; 

(理想情况下,而不是清除previousTitledocument.previousTitle = undefined;,我们会使用delete document.previousTitle;,但可悲的是,关于IE打破因为document是不是真的一个 JavaScript对象,它只是表现很像一个居多。)

您可能会想:我们去找head中的title元素,并使用其原始内容来恢复标题。 (这是我的想法。)但是,没有,设置document.title实际上更新title元素的内容在head,所以这是行不通的。你必须将原件保存在别的地方。

+1

很好的答案你理解我的模糊问题:)。是的,我明白你的意思,但这可能是最简单的方法。谢谢。 – Sphvn 2010-06-24 06:56:27

+0

@崎崎:啊,很好,很高兴帮助! :-) – 2010-06-24 07:00:50