Reputation: 83
how to get Element From an Iframe? i want when the attribute of an element that its in a frame is true; it show a text, and else show another text; (sorry for bad english!)
like that:
<!DOCTYPE html>
<html>
<head>
<title>document</title>
</head>
<body>
<iframe id="frame" src="">
<!--we think in frame there is a span tag with button id-->
<span id="button" aria-passed="true">sss</span>
</iframe>
<br>
<!--if its true-->
<p id="content1" style="display:none;">
true
</p>
<!--if its false-->
<p id="content2" style="display:none;">
false
</p>
<!--now we want that, if aria-passed=true show content1 else content2.-->
<script type="text/javascript">
var Frame = document.getElementById('frame');
if(new RegExp ("true","gim").test(frame.contentWindow.document.getElementById('button').aria-passed="true") == true) {
document.getElementById('content1').style.display="block";
}
else {
document.getElementById('content2').style.display="block";
}
</script>
</body>
</html>
now i want to say why this code does not work???? any ideas?
Upvotes: 1
Views: 10979
Reputation: 21
It's much easier if you use jquery.
Example Code:
var elementattibutevalue = $("#frameID").contents().find("#htmlelementID").attr("SampleAttribute");
Hope it helps. (^_^)
Upvotes: 1
Reputation: 60
I think the iframe in your code above is just a demonstration of how the loaded page code looks like? Take a look at this post Javascript - Get element from within an iFrame. Also change your 'Frame' variable to lowercase.
Upvotes: 0