locked
Microsoft edge show undefined for window.opener RRS feed

  • Question

  • User-893002196 posted

    Hi All,

    I have code as below, but getting error "Undefined" when running the page under Microsoft edge browser:

    var winType = window.opener;
    
    if (navigator.userAgent.search("Chrome") >= 0) {
          winType = window.opener.document;
    }
    else if (navigator.userAgent.search("Safari") >= 0 && navigator.userAgent.searc("Chrome") < 0) {
         winType = window.opener.document;
    }
    
    $("#BudgetId", winType).val(id);

    Please advise.

    Thanks.

    Regards,

    Micheale

    Friday, December 7, 2018 8:35 AM

Answers

  • User-893002196 posted

    Hi,

    Thanks everyone.

    I have solved it. Solution:

    var browser = new Browser();
    //get Master Id
    var winType = window.opener;
    if (browser.isIE)
    //This only works for IE browsers.
    winType = window.opener.document;
    if (browser.isNS)
    //This only works for non-IE browsers.
    winType = window.document;

    $("#BudgetId", winType).val(id);

    Thanks.

    Regards,

    Micheale

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 17, 2019 2:15 AM

All replies

  • User753101303 posted

    Hi,

    Never tried. This is  a link or window.open ? This is on the same domain ?

    Friday, December 7, 2018 9:27 AM
  • User-474980206 posted

    it appears to be a bug in edge, more prevelent with //localhost (CORS). try windows 10 1803. 

    a workaround, is to have the opener set a handler

       var popup = windows.open(...);
       popup.setBudgetId = function(id) {
           $('#BudgetId').val(id);
       };

     

    Friday, December 7, 2018 7:49 PM
  • User-271186128 posted

    Hi Micheale,

    but getting error "Undefined" when running the page under Microsoft edge browser:

    Which line did you encounter this error? Please check your code, whether you define the id variable, and use F12 developer tools to check whether you could find the BudgetId element.

    Based on your code, I create a sample using the following code, it seems that everything works well on my side.

    Code in parent page:

        <script src="../Scripts/jquery-1.10.2.min.js"></script>
        <script type="text/javascript">
            $(function () {
                $("#btnOpen").click(function () {
                    var popup = window.open("http://localhost:62524/Htmls/HtmlPage4.html", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
                });
            })
        </script>
    
            <input type="button" id="btnOpen" value="Open" />
    <input type="text" id="BudgetId" value="" />

    Code in child page:

        <script src="../Scripts/jquery-1.10.2.min.js"></script>
        <script type="text/javascript">
            $(function () {
                var winType = window.opener;
    
                if (navigator.userAgent.search("Chrome") >= 0) {
                    winType = window.opener.document;
                }
                else if (navigator.userAgent.search("Safari") >= 0 && navigator.userAgent.searc("Chrome") < 0) {
                    winType = window.opener.document;
                }
                var id = 1001;
                $("#BudgetId", winType).val(id);
            })
        </script>
    </head>
    <body>
       
    </body>

    The result as below:

     Best regards,
    Dillion

    Monday, December 10, 2018 3:28 AM
  • User-893002196 posted

    Hi,

    Thanks everyone.

    I have solved it. Solution:

    var browser = new Browser();
    //get Master Id
    var winType = window.opener;
    if (browser.isIE)
    //This only works for IE browsers.
    winType = window.opener.document;
    if (browser.isNS)
    //This only works for non-IE browsers.
    winType = window.document;

    $("#BudgetId", winType).val(id);

    Thanks.

    Regards,

    Micheale

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 17, 2019 2:15 AM