John Doe
John Doe

Reputation: 3691

How can I launch a PARENT jQuery function?

I'm trying to figure out how to launch a function from an iframe but the following example won't work, any ideas?

<input class='reply' onclick='parent.replytopost()' type='button' value='Reply' />

PARENT PAGE FUNCTION (In the body if that makes a difference):

<script>
  function replytopost(){
  alert("test");
  parent.document.getElementById('mainbar').innerHTML = "TEST";
  parent.document.getElementById('post_reply').show();
  }
</script>

Upvotes: 0

Views: 216

Answers (3)

changelog
changelog

Reputation: 4681

This might become an issue with security-tightened browsers (such as Safari).

I ran against the same type of problem recently, and I'm now a happy user of window.postMessage.

You will still have to reference it using window.parent but this will prevent the vast majority of issues to happen.

Upvotes: 1

genesis
genesis

Reputation: 50982

It works for me. Look here

Why do you call parent.* in non-iframe replytopost script?

Upvotes: 0

Amin Eshaq
Amin Eshaq

Reputation: 4024

Will window.opener work for you? I know it works from a parent to a newWindow. I don't know about iframe.

http://www.w3schools.com/jsref/prop_win_opener.asp

Upvotes: 0

Related Questions