Skip to content
Loading
How to send a java script object using window.open
+2
  • Ankit Kanojia
    Hello Sivaraj,
     
    Normally window.open method will be redirected or open specified URL passed as a parameter, So in case of you want to pass any object or value or Js Object, you just need to pass URL with query parameter and once that page is open you can retrieve from URL or from the query string. this is the formal approach that can help you out.
      
    1. window.open(url, name, style)    
    2.     
    3. URL like 'https://www.c-sharpcorner.com?param=value'  
    4.   
    5. //TO retrieve data or value from the query string or URL  

    6. new URLSearchParams(window.location.search)  
    Regards.
    +1
  • Harshal Limaye
    You can pass it using query params.
     
    Let's say you have a user object which you need to pass to example.com. You can do this by simply stringifying the object and sending it with query params.
    1. const user = { id: 1, name: 'harshal'};  
    2. window.open('http://www.example.com?user=' + JSON.stringify(user))  
    The URL in the browser will appear like this.
    1. http://www.example.com/?user={%22id%22:1,%22name%22:%22harshal%22}  
    To access this object you can simply use the following code.
    1. const params = new URLSearchParams(location.search);  
    2. const user = JSON.parse(params.get('user'));  
    3.   
    4. console.log(user);  
    5. // output: {id: 1, name: "harshal"}  
    +1
  • Edinbiro James
    Hi,
    Please refer this link https://javascript.info/popup-windows 
    +1