how to get the object from the window.open in window.opener in chrome

1k views Asked by At

hi i am not able to get the object which i am passing through window.open

      var obj= new Object();
     var newpage= '';
    var urlaspx= "urlaspx.aspx?sid=1&frameWidth=" + frameWidth;

newpage= window.open(urlaspx, obj, 'center:yes; dialogWidth:400px; dialogHeight:430px; help:0; 
  status:0; scroll:0; resizable:1'); 

in my urlaspx

<script type="text/javascript">
var obj= window.opener;
var name= obj.name;
var age= obj.age;
</script>

here the obj object is null pls help me on this

1

There are 1 answers

1
giuseppedeponte On

The second argument for window.open should be a string, for the new window name, not an object.

I don't think browsers allow you to pass data from one window to another like that. (cf. developer.mozilla.org/en-US/docs/Web/API/Window/open).

If you are the owner of both pages, you could add some parameters to the second page URL to pass data from one window to the other (like you do already for frameWidth).

const urlaspw = "urlaspx.aspx?"
  + "sid=1"
  + "&frameWidth=" + frameWidth
  + "&name=" + obj.name
  + "&age=" + obj.age;
const newpage = window.open(urlaspx, obj, 'center:yes; dialogWidth:400px; dialogHeight:430px; help:0; status:0; scroll:0; resizable:1'); 
    var obj = {};
    var currentLocation = window.location.toString()
    // or
    var currentSearch = window.location.search

    var params = currentSearch
      .split('?')[1]
      .split('&')
      .forEach(param => {
          obj[param.split('=')[0]] = param.split('=')[1]
       })
    var name = obj.name;
    var age = obj.age;