javascript 如何访问子窗口内的父窗口javascript变量(弹出窗口)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14941504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 22:59:36  来源:igfitidea点击:

how to access parent window javascript variable inside child window(pop-up)?

javascript

提问by emilly

I have html page which has global javascript variable with name custName="scott". I open the pop-up window with window.open.

我有一个 html 页面,其中包含 name 的全局 javascript 变量custName="scott"。我用window.open.打开弹出窗口。

Now if I access the custNameinside pop-up window with window.opener.custName, I get values as undefined. How do I access parent window javascript variable inside child window(pop-up)?

现在,如果我使用 访问custName内部弹出窗口window.opener.custName,我会得到值为undefined。如何在子窗口(弹出窗口)中访问父窗口 javascript 变量?

回答by emilly

window.opener.custNameworks. It was typo mistake.

window.opener.custName作品。这是打字错误。

回答by Naveen D Almeida

Try this to get the Query string in javaScript

试试这个来获取 javaScript 中的查询字符串

link.html?page=1

<script type="text/javascript">

        $.getUrlVar('page');
        $.extend({
              getUrlVars: function(){
              var vars = [], hash;
              var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&amp;');
              for(var i = 0; i &lt; hashes.length; i++)
              {
                   hash = hashes[i].split('=');
                   vars.push(hash[0]);
                   vars[hash[0]] = hash[1];
             }
             return vars;
        },
       getUrlVar: function(name){
           return $.getUrlVars()[name];
       }
 });

</script>