I’m trying to replace each textNode of the DOM tree using the following function:
//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);
}
});
}
It works but it throws 20 errors like this (Google Chrome, IE don’t throws):
Unsafe JavaScript attempt to access
frame with URL
http://cdn.apture.com/media/html/aptureLoadIframe.html?v=21872561
from frame with URL
http://c-jfmunoz:5000/SitePages/Home.aspx.
Domains, protocols and ports must
match.
Doing some debugging I look that it throws the exception when the textnode is being inserted into a web form.
I have to attach this JavaScript to a Sharepoint 2010 site. When viewed locally Chrome doesn’t throw the exception.
How can I fix this?
You cant get around the fact that it dont want to do iframes, thats just the way it is, but you can avoid the errors by replacing
With