将document.title设置为默认值

时间:2010-06-24 06:36:04

标签: javascript jquery html css

快点..

如果我设置警报文件。标题为“ALERT”。 然后想要在之后设置它是否有ezmode方式来执行此操作,或者是否将在链接标记上设置ID以将标题设置回ID。请注意它是一个在20多页上使用的外部脚本。

1 个答案:

答案 0 :(得分: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;

(理想情况下,我们不是使用previousTitle清除document.previousTitle = undefined;,而是使用delete document.previousTitle;,但遗憾的是因为document不是而导致IE中断真的一个JavaScript对象,它的行为非常像一个,主要是。)

您可能会想:让我们去找title中的head元素并使用其原始内容来恢复标题。 (这就是我的想法。)但是,不,设置document.title实际更新 titlehead元素的内容,这样就行不通了。你必须在其他地方保存原文。

相关问题