恶意的Safari的Javascript与document.write [英] Woes of Safari's Javascript with document.write
问题描述
我的问题只发生在Safari上。 IE,FF,Chrome和Opera都是完美无缺的。我正在向DOM添加一个对象(与YouTube完全相同,取决于ActiveX或NPAPI),因此,在确定写入对象类型后,我将其添加到DOM中:
My problem only happens on Safari. IE, FF, Chrome and Opera all work flawlessly. I am adding an object to the DOM (exactly the same way YouTube does it, depending on ActiveX or NPAPI) so after I determine the write object type I add it to the DOM via :
document.write(MyObject)
在页面的头部,所以js函数从身体调用可以访问它。它适用于除Safari之外的所有内容。我可以让Safari工作的唯一方法是在document.write之后添加一个警报!我甚至尝试使用setTimeout,但它工作一次,失败10。
At the head section of the page, so that js functions called from body can access it. It works on everything except Safari. The only way I can let Safari work is by adding an alert after document.write! I even tried setTimeout, but it works one time and fails 10.
推荐答案
Document.write在正文中无法正常工作本身和document.body.appendChild添加一个对象标记不起作用。
Document.write doesn't work correctly in the body itself, and document.body.appendChild to add an object tag doesn't work.
所以我做的是
var objectContainer = createElement("div");
objectContainer.innerHTML = "<object blah blah> <\/object>"; //<--notice the escaping of /
document.body.appendChild(objectContainer);
现在它可以在任何地方使用。
And now it works everywhere.
这篇关于恶意的Safari的Javascript与document.write的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!