1

という名前のページがありますparent.html。そこからモーダル ダイアログを呼び出しますchild.htmlchild.htmlモーダル ダイアログを閉じるためのリンク ボタンがあります。同時に、 からchild.htmlに値を渡したいと思いparent.htmlます。

子ページから親ページに値を送信するにはどうすればよいですか?

4

2 に答える 2

2

子ページ (child.html) が親ページと同じドメインにある場合、child.html から親ウィンドウの関数を呼び出すことができます。

子ページ (child.html) :

<a href="..." onclick="parent.callFromChildPage('ABC')">Button Title</a>

そして、親ページ (parent.html) で:

<script language="javascript">
function callFromChildPage(a_value){
    alert("A value from child window is :" + a_value); // 'ABC'
}
</script>

また、子ページ (child.html) で jQuery を使用できる場合は、次のように親ページの要素を直接設定できます。

<a href="..." onclick="$('#test', window.parent.document).html('ABC');">Button Title</a>
于 2012-12-19T07:32:11.180 に答える
0

基本的に、親ページで JavaScript 関数を定義し、子ページで を使用してこの関数を呼び出すだけopenerです。

window.openerを使用すると、開いているドキュメントの window オブジェクトを参照できます。

子 HTML:

<html>
  <head>
    <script type="text/javascript">
      $('a#child-link').click(function(e){
          e.preventDefault();
          var tmp = $('input#child-input').value();
          window.opener.getChildVar(tmp);
      });
    </script>
  </head>
  <body>
    <input type="text" name="child-text" id="child-input" value="test text" />
    <a href="#" id="child-link">link</a>
  </body>
</html>

親 HTML:

<html>
  <head>
    <script type="text/javascript">
      function getChildVar(val) {
        var received_val = val;
      }
    </script>
  </head>
</html>
于 2012-12-19T07:48:07.793 に答える