我嘗試使用下面的函數來替代DOM樹的每個textNode
時:不安全的JavaScript attept訪問幀錯誤在Chrome取代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級象這樣的錯誤(谷歌Chrome瀏覽器,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不會拋出異常。
我該如何解決這個問題?
這樣的作品,但現在這麼想的更換任何東西! – Caipivara 2011-01-27 14:40:28
我可以忽略這個錯誤?活得像它不會發生? – Caipivara 2011-01-27 14:54:35