Click here to Skip to main content
15,900,815 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am not getting the child nodes inside the IFrame.

I am not able to access the elements inside the Iframe and also.If I try to render google.com in Iframe I am getting the following error.
"Refused to display 'https://www.google.co.in/' in a frame because it set 'X-Frame-Options' to 'sameorigin'."

The following is another error for adding an event to IFrame
Blocked a frame with origin "http://localhost:53242" from accessing a cross-origin frame.

What I have tried:

code:
"<iframe id="display" src="https://www.w3schools.com/"></iframe>"
script:
elements = document.querySelectorAll('iframe>*');
Posted
Updated 30-May-17 3:15am

1 solution

You can't access the DOM of pages in an iframe unless they have been programmed such that they give your site access. This is for security reasons. Furthermore when it comes to google they have configured their site such that you can't use it in an iframe at all. There is no way to circumvent these security measures otherwise they would be pointless and furthermore there is no ethical reason to do this kind of thing either.
 
Share this answer
 
Comments
Member 13223623 31-May-17 0:50am    
Thank you for the clarification. Can u please suggest me by which way I can do this task?

Task: User gives enters the URL as input and I should load the page and the User should be able to select the which part of the page he want to get the DOM Elements.

What I have Done is:
By using the HTMLagility pack I am able to access all the DOM Elements used in the Webpage.By Taking the URL as the input.

HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(Url);
foreach (HtmlNode node in doc.DocumentNode.Descendants())
{
Console.WriteLine(node.Name + " " + node.GetAttributeValue("Id", true));
}

But I'm able to the above task.could u help in this?
Thanks in advance
F-ES Sitecore 31-May-17 4:10am    
You can't do that using a webpage and js, you'd need to write a browser plug-in or something like that.

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