我正在MS Dynamics CRM 2011表单上的OnLoad事件中运行一段JScript代码,并希望通过脚本设置文档标题(即此页面的IE窗口/选项卡中显示的内容)。
我打了以下电话:
document.title = newtext;
但这行不通。当我使用 F12 检查正在发生的情况时,我看到预先存在的 document.title 值是"持有:"。但是,我的浏览器中实际选项卡的 document.title 是"持有:- Microsoft Dynamics CRM"
我认为问题可能是我在子窗体(或者可能是iFrame?)中工作,而不是在用户导航到的实际文档中工作。有什么方法可以设置父文档的标题吗?
不确定这是否适合您,但这是我们的 setDisplayName 函数,可更新标题和 CRM Div 显示名称:
/*
Updates the display name of the entity, both in the name div, and the Page Title
*/
setDisplayName: function (name) {
// Updates the Document Title
var title = parent.document.title;
var start = title.indexOf(':') + 2;
var end = title.lastIndexOf('-') - 1;
parent.document.title = title.substring(0, start) + name + title.substring(end);
// Sets the div Name
document.getElementById("form_title_div").childNodes[2].childNodes[0].innerText = name;
}