Search code examples
xmldocumentwindow.openmicrosoft-edge

Pass object to browser with window.open in Edge


In case of Edge browser say Browser One, passing a custom argument to second Browser. if I pass a string it is available in the second window. But, if I pass an object (say XMLDocument) in the second window, I could not serialzetoString.

var myWin = window.open(...);
myWin.customArg = 'string parameter'  // Works
myWin.customArg = xmlObject  // Doesnt Work

in the second window,

new XMLSerializer().serializeToString(xmlDoc) 

throws xml parser exception.

Can any one help in resolving this? Same code works fine for Chrome.

Edit - Sample code of Parent Window is here -

<html>
<head>
    <script type="text/javascript">
        function OpenWindow()
        {
            var objXML = '<SelectedCharts><Chart ColumnNo="1" ChartName="E0PK" GroupName="test" OrderNo="1" /></SelectedCharts>';
            var xmlDoc = new DOMParser().parseFromString(objXML,'text/xml');
            var dialog = window.open("Child_Window.htm", "title", "width=550px, height= 350px,left=100,top=100,menubar=no,status=no,toolbar=no");
            dialog.dialogArguments = xmlDoc ;
            dialog.opener = window;
        }
    </script>
</head>
<body>
    <span>Passing an XML Object to the child window:</span>
    <input type="button" value="Open Popup" onclick="OpenWindow()" />
</body>
</html>

And the sample code of Child window is here -

<html>
<head>
    <script type="text/javascript">
        function onBodyLoad()
        {
            alert(new XMLSerializer().serializeToString(window.dialogArguments));
        }
    </script>
</head>
<body onload="onBodyLoad()">
    <span>This is child window.</span>
</body>
</html>

Solution

  • The code snippet shown in the question works fine for Chrome browser. And to pass the context to another window in case of Edge browser, follow the below method.

    declare a global variable and set it in the parent window And, access the varable in the child window using window.opener.

    And sample code is provided in Pass custom arguments to window.open in case of Edge browser