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?
2 Answers 2
It's much easier if you use jquery.
Example Code:
var elementattibutevalue = $("#frameID").contents().find("#htmlelementID").attr("SampleAttribute");
Hope it helps. (^_^)
answered Oct 16, 2013 at 10:24
not.your.ordinary.girl
211 silver badge3 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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.
Comments
lang-js
.aria-passedisn't a property - that code is looking for theariaproperty and subtracting some undefinedpassedvariable. And the="true"right after that should definitely be an error as you're trying to assign an expression a value, which isn't possible. Also, JavaScript is case sensitive, so you can't declare a variable asFrameand then useframe