Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

I have one textbox and a button. When I am entering all the special characters in textbox and clicked on button it should return me the same text which I entered in textbox. For this I am using DOMParser function which is working fine in IE but not in Iframme. My application opens in Iframe and need to fix this problem.

Kindly help.

Thanks.

What I have tried:

Not sure how to fox this issue in iFrames
as DOMParser is not for iFrame. Below is my code which is working fine in IE but not in iFrame.
Function parseText(string){
Var parser = new DOMParser;
Var dom = parser.parseFromString(
'<!doctype.html><body>'+ string,'text/html');
return dom.body.textcontext;
}
Posted
Updated 9-Nov-18 2:45am
v3
Comments
CHill60 9-Nov-18 6:08am    
Not sure how we can fix any problem without seeing any code
F-ES Sitecore 9-Nov-18 6:19am    
You're either using DOMParser incorrectly (we don't know as we can't see your code) or the issue is that the site in the iframe is from a different host as the one your js is on as the browser won't let you script against sites from a different host.
Telstra 9-Nov-18 6:30am    
Hi F-ES Sitecore,

Both iframe and js are on the same domain.

Thanks,
Nilesh

Telstra 9-Nov-18 6:20am    
Function parseText(string){
Var parser = new DOMParse;
Var dom = parser.parseFromString(
'<!doctype.html>'+ string,'text/html');
return dom.body.textcontext;
}
Richard MacCutchan 9-Nov-18 6:31am    
Please edit your question and show the code there. Also explain exactly what happens when your code runs.

1 solution

You need to keep in mind that when you open an <iframe> on your page it is, for most purposes, a separate location from your regular page. Thus, depending upon where you call your DOM accessing functionality, you need to keep in mind that it will only look at it's own page - that is, it's own scope.

As an example, you may open a copy of a page inside of itself. It would then have the same id='' values in both the parent and child pages. The DOM can tell them apart because they are in "different scopes".

Note the use in the previous paragraph of 'parent' and 'child'. There is the ability to be in one scope and access the other using references to the parent or child.

So - depending upon where you request the data relative to where it is, you will see different results (like failure). Consider this - you may solve your problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900