How to open maximized window with Javascript?

前端 未结 5 1410
独厮守ぢ
独厮守ぢ 2020-11-28 07:45

I\'m using Javascript\'s self.open() to open a link in a new window and i\'d like that window to be maximized. I tried the fullscreen=yes option, w

5条回答
  •  隐瞒了意图╮
    2020-11-28 08:23

    The best solution I could find at present time to open a window maximized is (Internet Explorer 11, Chrome 49, Firefox 45):

      var popup = window.open("your_url", "popup", "fullscreen");
      if (popup.outerWidth < screen.availWidth || popup.outerHeight < screen.availHeight)
      {
        popup.moveTo(0,0);
        popup.resizeTo(screen.availWidth, screen.availHeight);
      }
    

    see https://jsfiddle.net/8xwocrp6/7/

    Note 1: It does not work on Edge (13.1058686). Not sure whether it's a bug or if it's as designed (I've filled a bug report, we'll see what they have to say about it). Here is a workaround:

    if (navigator.userAgent.match(/Edge\/\d+/g))
    {
        return window.open("your_url", "popup", "width=" + screen.width + ",height=" + screen.height);
    }
    

    Note 2: moveTo or resizeTo will not work (Access denied) if the window you are opening is on another domain.

提交回复
热议问题