Laine
Laine

Reputation: 79

Change div text in parent of iframe?

I am trying to change the text in the following div within the parent iframe.

(I am running the code from within the iframe)

<div class="hello1">I want to change this</div>

How could i accomplish this?

Ive tried:

$("body #hello1", top.document).text("HELLO");

But i get this error:

Unsafe JavaScript attempt to access frame

Any ideas?

Upvotes: 0

Views: 992

Answers (2)

AlgoDragon
AlgoDragon

Reputation: 1

I have also used the following solution when you need to change the parent frame border text when a click event is fired within an iframe and the user has tested the submit button:

<script>
$("button").click(function(){
    if ($('.email').val() !== 'Enter Your Best Email'){
        $('.x_out', top.document).text('<< Back to the main page');
        }
});
</script>

Upon testing the submit button once, the user is prompted with a tooltip reminder of "!Please fill out this field." via the HTML5 onclick="validate();"

Upon testing the submit button the second time, the border enclosing the iframe has text within a closing link change to guide them back to the main page (i.e. the closing link closes the iframe and clicking the button within the iframe changes this text in the parent frame).

Upvotes: 0

Jay Blanchard
Jay Blanchard

Reputation: 34426

The div has a class of hello1 and the code you wrote is trying to access the id hello1. Change to this -

$(".hello1", top.document).text("HELLO");

Upvotes: 2

Related Questions