【发布时间】:2011-06-16 14:22:43
【问题描述】:
我正在尝试使用以下函数替换 DOM 树的每个 textNode:
//Replace each word objective with reposition in each control of the actual jQuery object
jQuery.fn.replaceEachOne = function (objective, reposition) {
var regExp = new RegExp('([\\s]'+objective+'[\\s])', "igm");
this.contents().each(function(){
if (this.nodeType == 3) {//if is a Node.TEXT_NODE, IE don't have Node object
//console.log("pName: "+this.parentNode.nodeName+" pType: "+this.parentNode.nodeType+" Data: " + this.parentNode.data);
if(this.data.search(regExp) != -1){
var temp = document.createElement("span");
temp.innerHTML = this.data.replace(regExp, reposition);
//Insert the new one
this.parentNode.insertBefore(temp, this);
// Remove original text-node:
this.parentNode.removeChild(this);
}
}
else{
$(this).replaceEachOne(objective, reposition);
}
});
}
它可以工作,但它会抛出 20 个这样的错误(谷歌浏览器,IE 不会抛出):
不安全的 JavaScript 尝试访问 带有 URL 的框架 http://cdn.apture.com/media/html/aptureLoadIframe.html?v=21872561 从带有 URL 的框架 http://c-jfmunoz:5000/SitePages/Home.aspx。 域、协议和端口必须 匹配。
进行一些调试,我发现它在将 textnode 插入 Web 表单时引发了异常。
我必须将此 JavaScript 附加到 Sharepoint 2010 站点。在本地查看时,Chrome 不会引发异常。
我该如何解决这个问题?
【问题讨论】:
标签: javascript jquery dom google-chrome