简体   繁体   English

在新窗口中加载网页时,全屏模式不起作用

[英]Full Screen mode not working while loading the web page in a new window

I used the following code segment to move from A.aspx web page to B.aspx web page and I need to load the B.aspx page in full screen mode in a separate window. 我使用以下代码段从A.aspx网页移动到B.aspx网页,并且需要在单独的窗口中以全屏模式加载B.aspx页面。 I am able to load the content on a separate window but unable to make it to display in full screen. 我能够将内容加载到单独的窗口中,但无法使其全屏显示。 The window just appears to the half of the screen 窗口仅出现在屏幕的一半

Response.Redirect("B.aspx", "", "fullscreen=yes");

I have tried it with the ScriptManager as well but again I am facing the same problem. 我也使用ScriptManager进行了尝试,但是我又遇到了同样的问题。 Following is the code segment. 以下是代码段。

string url = "B.aspx";
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "window.open(' " + url + "', '', 'fullscreen=yes,resizable=no,scrollbars=yes,toolbar=no,menubar=no,status=yes' );", true); 

I have also tried setting the width and height of the window and got the same output! 我也尝试设置窗口的宽度和高度,并得到相同的输出!

Note: The problem occurs on Google Chrome and Microsoft Edge browsers. 注意:在Google Chrome和Microsoft Edge浏览器上会出现问题。 When I run the program on Firefox, the page got loaded in full screen. 当我在Firefox上运行该程序时,页面全屏加载。 Is this a browser problem or is there any way to achieve this where it is compatible with all the browsers? 这是浏览器问题,还是可以通过与所有浏览器兼容的方法来实现?

There are several mistakes and recommendations here: 这里有一些错误和建议:

1) Response.Redirect() method only accept a maximum of 2 parameters, therefore you cannot use fullscreen=yes as third parameter. 1) Response.Redirect()方法最多只能接受2个参数,因此不能将fullscreen=yes用作第三个参数。

2) fullscreen=yes as window.open() parameter only works for IE (and older Firefox), but not all versions supported ( MDN reference ). 2) fullscreen=yes as window.open()参数仅适用于IE(和较旧的Firefox),但不支持所有版本( MDN参考 )。 You need to use browser specific APIs on the target page instead. 您需要在目标页面上使用浏览器特定的API。

Hence, as mentioned before, you should add a function to call fullscreen API depending on the client browser: 因此,如前所述,您应根据客户端浏览器添加一个函数来调用全屏API:

function fullScreenMode(element) {
    if(element.requestFullscreen)
        element.requestFullscreen();
    else if(element.mozRequestFullScreen)
        element.mozRequestFullScreen();
    else if(element.webkitRequestFullscreen)
        element.webkitRequestFullscreen();
    else if(element.msRequestFullscreen)
        element.msRequestFullscreen();
}

Then modify RegisterStartupScript like this: 然后像这样修改RegisterStartupScript

ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", 
              "window.open('" + url + @"', '', 'resizable=no,scrollbars=yes,toolbar=no,menubar=no,status=yes' );", true);

And call fullScreenMode(document.documentElement) function on the target page when user triggering certain DOM event, because some browsers put limitations to prevent pop-up window abuse in similar way to window.open() function. 当用户触发某些DOM事件时,请在目标页面上调用fullScreenMode(document.documentElement)函数,因为某些浏览器以类似于window.open()函数的方式进行了限制,以防止弹出窗口滥用。

Related issue: 相关问题:

How to open a web page automatically in full screen mode 如何以全屏模式自动打开网页

Setting the whole window to be fullscreen in recent browsers 在最近的浏览器中将整个窗口设置为全屏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM