Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
475 views
in Technique[技术] by (71.8m points)

javascript - JQuery - Write to opener window

I have an HTML page that opens another page via JavaScript. When a user clicks a button in the other page, I want to post a message in a DIV of the opening page via JQuery. I cannot put my finger on it, but I cannot seem to get this to work. Here is my opener page

<html>
  <head>
    <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
  </head>

  <body>
    <input type="button" onclick="window.open('dialog.html', '_blank', 'height=200, width=300');" value="launch!" />
    <div id="testDiv"></div>
  </body>
</html>

When the user clicks the "launch!" button, a dialog will appear. The code for the dialog looks like this:

<html>
  <head>
    <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
  </head>

  <body>
    <input type="button" onclick="updateOpener()" value="Update Opener" />
    <script type="text/javascript">
      function updateOpener()
      {
        var testDiv = window.opener.jQuery("#testDiv");
        if (testDiv != null) {
      alert("here");
      testDiv.html("Updated!");
        }
      }
    </script>
  </body>
</html>

Surprisingly, the alert box appears. However, I cannot seem to update the HTML of the DIV in my opening page. Does anyone know how to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You're referencing "confirmDiv". Where is that DIV?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...