简体   繁体   English

如何启动PARENT jQuery函数?

[英]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? 我试图弄清楚如何从iframe启动功能,但以下示例将不起作用,有任何想法吗?

<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>

This might become an issue with security-tightened browsers (such as Safari). 对于安全性较高的浏览器(例如Safari),这可能会成为问题。

I ran against the same type of problem recently, and I'm now a happy user of window.postMessage . 我最近遇到了相同类型的问题,现在我是window.postMessage的快乐用户。

You will still have to reference it using window.parent but this will prevent the vast majority of issues to happen. 您仍然必须使用window.parent来引用它,但这将防止发生绝大多数问题。

Will window.opener work for you? window.opener对您window.opener吗? I know it works from a parent to a newWindow. 我知道它可以从父级到newWindow。 I don't know about iframe. 我不了解iframe。

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

It works for me. 这个对我有用。 Look here 这里

Why do you call parent.* in non-iframe replytopost script? 为什么在非iframe回复投稿脚本中称呼parent。*?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM