1

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?

asked May 25, 2013 at 7:00
1
  • .aria-passed isn't a property - that code is looking for the aria property and subtracting some undefined passed variable. 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 as Frame and then use frame Commented May 25, 2013 at 7:24

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

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.

answered May 25, 2013 at 7:12

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.