简体   繁体   English

document.title问题ie8

[英]document.title problems ie8

为什么IE8无法使用document.title =“test title”更改文档标题;

Following works on IE8 for me. 以下为我的IE8工作。 But I did get the ActiveX security popup, so perhaps your IE8 is not set to prompt for these issues and just deny scripting. 但我确实得到了ActiveX安全弹出窗口,所以也许你的IE8没有设置为提示这些问题而只是拒绝编写脚本。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test</title>
<script type="text/javascript">
    function changeTitle() {
        document.title = 'Foobar';
    }
</script>
</head>
<body onload="changeTitle()">
</body>
</html>

Really? 真? Using document.title = 'Foo Bar'; 使用document.title = 'Foo Bar'; has always worked for me. 一直为我工作。 Is your script even executing? 你的脚本是否正在执行?

Try shoving this right before the document.title = ... : 尝试在document.title = ...之前推迟这个:

alert('I work.');

If you don't get an alert box, your script isn't even running. 如果您没有收到警告框,则您的脚本甚至都没有运行。

found this: http://support.microsoft.com/kb/296113 发现了这个: http//support.microsoft.com/kb/296113

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JAVASCRIPT">

function runTest()
{
    var s ="We should set this as the new title" 
    var mytitle = document.createElement("TITLE");
    mytitle.innerHTML = s;
    alert(s);       
    document.documentElement.childNodes[0].appendChild(mytitle);

}
function fix()
{
    var s = "Now we change the title";
    alert(s);
    document.title = s; 
}
</SCRIPT>
</HEAD>
<BODY>
<input type="button" value="Problem" onclick="runTest()"/>
<input type="button" value="Workaround" onclick="fix()"/>
</BODY>

for me this is works in IE 9,8,7 对我来说,这适用于IE 9,8,7

maybe you dont call your function, or there is something which not works. 也许你不打电话给你的功能,或者有些东西不起作用。

the document.title must work! document.title必须工作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM