How to access the parent window of a javascript variable inside a child window (popup)?

I have an html page with a global javascript variable named custName="scott". I open a popup with window.open.

Now, if I get a popup custNameinside window.opener.custName, I get the values ​​as undefined. How to access javascript variable of parent window inside child window (popup)?

+5
source share
2 answers

window.opener.custNameworks. It was a typography error.

+9
source

Try this to get the query string in 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>
0
source

All Articles