Reputation: 540
I had the wrong impression that using Greasemonkey would allow me unrestricted access to iframe's elements as jQuery selectors..
The HTML page example:
<html>
<body>
<div id='content'>
//Here is the first iframe
<iframe src='bla.php'>
<html>
<body>
<div id='content2'>
//Here another iframe is inserted
<iframe src='bla2.php'>
//Here some simple elements
<div id="goal">
My password is Secret
</div>
</iframe>
</div>
</body>
<html>
</iframe>
</div>
</body>
<html>
So I'm trying to find if the #goal selector contains Secret, and tried using
$('#goal').text().search('Secret');
Obviously it doesn't work, tried getting the whole DOM as a variable and used the variable.indexOf('Secret') .. but after debugging, the DOM content does not contain the iframes contents.
Any solution I may use ? Some Greasemonkey settings I may apply ?. Thank you.
Upvotes: 0
Views: 758
Reputation: 540
Iframes are treated different, jQuery has a second optional argument, related to the used document DOM, default is document, and setting it to the iframe document will work.
$('#goal', frames[0][0].document ).text().search('Secret');
Upvotes: 1