window.open() parameters ignored when opening cross-origin window in Microsoft Edge

∥☆過路亽.° 提交于 2021-02-05 09:27:51

问题


In Microsoft Edge, the following snippet will ignore the options passed to window.open() when url is a different origin than the current domain. But works it works fine in Chrome and Firefox, and when the domain is the same origin.

const popupWindow = window.open(
    url,
    title,
    'menu=no,toolbar=no,width=700,height=600,scrollbars=1,resizable=0,' +
        'directories=no,location=no,screenX=0,screenY=0,top=48,left=48',
);

I found a hacky workaround to get the window to size properly but this is really annoying and you can see it redirect the page.

const popupWindow = window.open(
    "/#",
    title,
    'menu=no,toolbar=no,width=700,height=600,scrollbars=1,resizable=0,' +
        'directories=no,location=no,screenX=0,screenY=0,top=48,left=48',
);
popupWindow.location.href = url;

How do I make this work on Microsoft Edge? Why is Microsoft Edge ignoring my size and other parameters? Is this a bug?


回答1:


I try to check the issue and it looks like security settings related issue.

I suggest you modify the below Internet Options settings.

(1) Enabled the Access data sources across domains option.

Internet Options -> Security (Tab) -> Custom Level -> Miscellaneous -> Access data sources across domains -> Set to Enabled

(2) Disabled the Protected mode.

Internet Options -> Security (Tab) -> uncheck Enable Protected mode for Internet & Local Intranet

(3) Add both domains to the trusted site list.

Internet Options -> Security (Tab) -> Trusted sites -> Sites -> Add both domains to the list.

(4) Uncheck Require server verification(https:):

Internet Options -> Security (Tab) -> Trusted site -> Sites -> Uncheck Require server verification(https:) -> enter localhost url & click on add button.

After modifying the above settings, I tested this code.

const popupWindow = window.open(
    "https://Bing.com",
    "Microsoft page",
    'menu=no,toolbar=no,width=700,height=600,scrollbars=1,resizable=0,' +
        'directories=no,location=no,screenX=0,screenY=0,top=48,left=48',
);

Output in Microsoft Edge 44.18362.1.0 :




回答2:


For me it is working correctly so the problem may be the version of Edge you are using. You can use caniuse.com to check whether you can use things or not. However, since you have found this hacky way of using it you can turn it into a function like this:

   function popup(url, title){
     const popupWindow = window.open(
       "/#",
       title,
       'menu=no,toolbar=no,width=700,height=600,scrollbars=1,resizable=0,' +
       'directories=no,location=no,screenX=0,screenY=0,top=48,left=48',
     );
     popupWindow.location.href = url;
   }

And now you can use the function popup.

By the way, I can see you are using ES6. Make sure your version of Edge supports const.



来源:https://stackoverflow.com/questions/59547823/window-open-parameters-ignored-when-opening-cross-origin-window-in-microsoft-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!