Answer the question
In order to leave comments, you need to log in
How to organize iframe parsing using javascript?
Good night, dear friends, there was a need to parse iframe content. You can view the source code of the document in the iframe through any browser, but something has not yet been parsed. I'm sorry that maybe many of my codes are not correct, I just started learning javascript.
So now we have:
var iframe = document.getElementById('happyFrame');
var frameDocs = iframe.contentDocument || iframe.contentWindow.document;
var link = frameDocs.getElementsByClassName('name');
alert(link.length);
<div class="item_info">
<a href="http://yyxxhh.com/u1jj12232lj" class="name" target="_blank">Мялка-палка</a>
</div>
Answer the question
In order to leave comments, you need to log in
As iframe.contentDocument documentation says
Those. this property is available only for frames that are on the same domain as the current document (for security purposes, for example, so that you don’t load social network messages in the frame and parse them)
However, if you want and really, really need to, you can do cross-domain ajax- request for the address of the frame using YQL (how exactly, you can learn more in this article), and it’s convenient to parse the necessary information.
Here, for example, a quick sketched example - parses the name of the last added character from a frame on a foreign domain and, accordingly, a picture with it output.jsbin .com/todetucede
If the iframe contains content from another domain, then getting access to it from the outside is quite problematic - there are quite evil security settings.
An example of an article describing them habrahabr.ru/company/mailru/blog/210050
In general, it is easier to parse documents on the server side.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question