繁体   English   中英

x-ms-window命令拉动和链接屏幕分辨率的

[英]x-ms-window command pulling and linking screen resolution's

好的,这是我的代码。 我试图让它嵌入基于Windows 8.1应用程序的屏幕分辨率的网页,但是我该如何在.js脚本中调用变量。

<body>
<script>
function myFunction() {
    var x = screen.width;
    var y = screen.height;
    document.getElementById('insert').width = x;
    document.getElementById('insert').height = y;
}
</script>
<x-ms-webview id="insert" src="http://subgamer.com" width=0 height=0 ></x-ms-webview>

请与代码一起解释!

我强烈建议使用像JQuery这样的库,因为它会使您的代码更加整洁并且功能强大。 只需使用以下代码行即可完成此操作:(对于与Web相连的网站,如果是供本地使用,则需要在本地下载文件)

<script type="text/javascript" src="https://code.jquery.com/jquery-latest.min.js"></script>

然后,插入以下代码将很简单:

$(function(){
    $('#insert').height($(window).height());
    $('#insert').width($(window).width());
});

$(function(){ }); 告诉它在页面加载后运行。 $('#insert')选择ID为'insert'的元素,其余元素仅分配高度和宽度值。

如果窗口可以随时调整大小,则可以将其放入函数中

function resizeInsert(){
    $('#insert').height($(window).height());
    $('#insert').width($(window).width());
}

并在页面加载和屏幕调整大小时调用它,如下所示:

$(function(){
    resizeInsert();
});

$( window ).resize(function() {
    resizeInsert();
});

这样,您的'insert'元素将始终保持窗口的完整大小。

暂无
暂无

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

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