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?

ARAS
  • 83
  • 1
  • 3
  • 8
  • `.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` – Ian May 25 '13 at 07:24

2 Answers2

1

It's much easier if you use jquery.

Example Code:

var elementattibutevalue = $("#frameID").contents().find("#htmlelementID").attr("SampleAttribute");

Hope it helps. (^_^)

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.

Community
  • 1
  • 1
sarahm
  • 60
  • 1
  • 7