• <i id='ZRT5c'><tr id='ZRT5c'><dt id='ZRT5c'><q id='ZRT5c'><span id='ZRT5c'><b id='ZRT5c'><form id='ZRT5c'><ins id='ZRT5c'></ins><ul id='ZRT5c'></ul><sub id='ZRT5c'></sub></form><legend id='ZRT5c'></legend><bdo id='ZRT5c'><pre id='ZRT5c'><center id='ZRT5c'></center></pre></bdo></b><th id='ZRT5c'></th></span></q></dt></tr></i><div id='ZRT5c'><tfoot id='ZRT5c'></tfoot><dl id='ZRT5c'><fieldset id='ZRT5c'></fieldset></dl></div>
      <bdo id='ZRT5c'></bdo><ul id='ZRT5c'></ul>
    1. <legend id='ZRT5c'><style id='ZRT5c'><dir id='ZRT5c'><q id='ZRT5c'></q></dir></style></legend>

        <tfoot id='ZRT5c'></tfoot>

      1. <small id='ZRT5c'></small><noframes id='ZRT5c'>

      2. window.opener 不正确

        window.opener is not right(window.opener 不正确)

        • <bdo id='bF9vD'></bdo><ul id='bF9vD'></ul>

            <tbody id='bF9vD'></tbody>
        • <tfoot id='bF9vD'></tfoot>
          <i id='bF9vD'><tr id='bF9vD'><dt id='bF9vD'><q id='bF9vD'><span id='bF9vD'><b id='bF9vD'><form id='bF9vD'><ins id='bF9vD'></ins><ul id='bF9vD'></ul><sub id='bF9vD'></sub></form><legend id='bF9vD'></legend><bdo id='bF9vD'><pre id='bF9vD'><center id='bF9vD'></center></pre></bdo></b><th id='bF9vD'></th></span></q></dt></tr></i><div id='bF9vD'><tfoot id='bF9vD'></tfoot><dl id='bF9vD'><fieldset id='bF9vD'></fieldset></dl></div>

          <small id='bF9vD'></small><noframes id='bF9vD'>

              • <legend id='bF9vD'><style id='bF9vD'><dir id='bF9vD'><q id='bF9vD'></q></dir></style></legend>
                  本文介绍了window.opener 不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在打开一个弹出窗口,并希望在其中进行单击操作,从而导致在打开它的页面中执行一些 jQuery.我在网上找到的所有内容都表明我应该能够使用 window.opener 做到这一点,(例如 JQuery - Write打开窗口)

                  I'm opening a popup and want to have a click action in it cause the execution of some jQuery in the page that opened it. Everything I find online says I should be able to do that with window.opener, (e.g. JQuery - Write to opener window)

                  但是当我 console.log window.opener 时,它只是真实的",而不是真实的对象.window.opener.jQuerywindow.opener.$ 和 'window.opener.document' 一样未定义.

                  But when I console.log window.opener, it's just 'true', not a real object. window.opener.jQuery is undefined as is window.opener.$ and 'window.opener.document'.

                  这是打开窗口的代码:

                  window.open('http://google.com' , "moderatorWindow", 'width=300, height=300');
                  

                  这是在 Safari 中.其他页面能够启动一个弹出窗口,当我在这些页面上检查 window.opener 时,我得到了一个真实的对象.我做错了什么?

                  This is in Safari. Other pages are able to launch a popup and when I inspect window.opener on those, I get a real object. What am I doing wrong?

                  推荐答案

                  由于同域策略规则,您的变量为 true 而不是对象.就像 iframe 一样,如果您打开的弹出窗口不在同一个域或子域中,那么在您创建它之后它就会丢失.如果我可以说,在我的网站上打开一个(隐藏的)iframe 到 gmail.com 并能够阅读您的电子邮件,那么网络将是一个非常不安全的地方.

                  Your variable is true and not an object because of same-domain policy rules. Just like an iframe, if the popup you open is not on the same domain or sub-domain then it is lost to you after you create it. The web would be a very unsecure place if I could say, open a (hidden) iframe on my site to gmail.com and was able to read your email.

                  即使弹出窗口位于子域上,您也必须做额外的工作并将两个窗口的 document.domain 值设置为根域(例如 mydomain.com).这是为了确保弹出的站点希望其父级知道(再次考虑安全性,如果我的 coke.ning.com 社区可以打开一个隐藏的 iframe 到您的 pepsi.ning.com 并蛮力尝试登录等)

                  Even if the popup is on a sub-domain you have to do extra work and set the document.domain value of both windows to the root domain (eg. mydomain.com). This is to ensure that the popped-up site wants to be known to its parent (again, think security, if my coke.ning.com community could open a hidden iframe to your pepsi.ning.com and do brute force attempts at a login, etc.)

                  为了证明我的观点,请尝试访问 google.com 并打开 Firebug(如果您使用的是 Safari 或 Chrome,则打开 Inspector)并执行以下操作:

                  To prove my point try actually going to google.com and opening up Firebug (or Inspector if you're using Safari or Chrome) and doing:

                  var bob = window.open('http://google.com' , "moderatorWindow", 'width=300, height=300');
                  bob.window.location.href; // returns "http://www.google.com/"
                  

                  最后,您可以随意在子页面上调用 jQuery 来修改同一页面上的元素,反之亦然,但您不能在一个页面上使用 jQuery 来修改另一个页面的 dom.几年前我尝试过这个尝试节省一些加载时间,除非有什么改变,否则它不起作用.jQuery 似乎绑定到创建它的窗口对象.奇怪的事情发生了.

                  Lastly, feel free to call jQuery on the child page to modify elements on the same page and vice-versa but you can't use jQuery from one page to modify the dom of the other page. I tried this a few years ago to try to save on some loading time and, unless something has changed, it doesn't work. jQuery seems to be bound to the window object of where it was created. Weird things happen.

                  这篇关于window.opener 不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Fetch multiple links inside foreach loop(在 foreach 循环中获取多个链接)
                  Backbone Fetch Request is OPTIONS method(Backbone Fetch Request 是 OPTIONS 方法)
                  Fetch API leaks memory in Chrome(Fetch API 在 Chrome 中泄漏内存)
                  How can I download and save a file using the Fetch API? (Node.js)(如何使用 Fetch API 下载和保存文件?(Node.js))
                  Send blob data to node using fetch, multer, express(使用 fetch、multer、express 将 blob 数据发送到节点)
                  Sending a custom User-Agent string along with my headers (fetch)(发送自定义用户代理字符串以及我的标头(获取))

                  <legend id='4mJf0'><style id='4mJf0'><dir id='4mJf0'><q id='4mJf0'></q></dir></style></legend>
                • <tfoot id='4mJf0'></tfoot>
                    <tbody id='4mJf0'></tbody>
                  • <i id='4mJf0'><tr id='4mJf0'><dt id='4mJf0'><q id='4mJf0'><span id='4mJf0'><b id='4mJf0'><form id='4mJf0'><ins id='4mJf0'></ins><ul id='4mJf0'></ul><sub id='4mJf0'></sub></form><legend id='4mJf0'></legend><bdo id='4mJf0'><pre id='4mJf0'><center id='4mJf0'></center></pre></bdo></b><th id='4mJf0'></th></span></q></dt></tr></i><div id='4mJf0'><tfoot id='4mJf0'></tfoot><dl id='4mJf0'><fieldset id='4mJf0'></fieldset></dl></div>
                      1. <small id='4mJf0'></small><noframes id='4mJf0'>

                            <bdo id='4mJf0'></bdo><ul id='4mJf0'></ul>