繁体   English   中英

在内容页面中使用JavaScript获取页面尺寸

[英]Get page dimensions using JavaScript in a Content Page

我正在尝试在内容页面(参考母版页)中使用javascript方法来获取当前屏幕尺寸,并将其写入标签。

到目前为止,我还没有运气。 我尝试在母版页和内容页中都这样做,但是该方法根本无法正常工作。

有人可以为此提供解决方案吗?

母版页:

<head runat="server">
    <title>Lake, Smit People</title>
    <!--[if IE ]>  
     <link rel="stylesheet" type="text/css" href="ProfileStypeSheetIE.css" />
    <![endif]-->  
    <!--[if !IE]>-->  
    <link href="ProfileStypeSheet.css" rel="stylesheet" type="text/css" />
    <!--<![endif]-->  

    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>

    <style type="text/css">
        .style1 { width: 378px; }
    </style>
</head>

Default.aspx

<asp:Content ID="Content5" ContentPlaceHolderID="head" Runat="Server">

<script type="text/javascript">

    var height = screen.height;
    document.getElementById('<%= hiddenLabel.ClientID%>').value = height;

</script>

</asp:Content>

您好,您可以尝试使用这些代码行,您的具体情况是第三个(clientHeight和clientWidth)

document.body.scrollWidth, document.body.scrollHeight // for the full size of the document
 
document.body.offsetWidth, document.body.offsetHeight //to the displayed size
 
document.body.clientWidth, document.body.clientHeight //customer for size displayed

您是否尝试过追踪?

<a href="javascript:alert
  ('Your resolution is ' + screen.width + 'x' + screen.height);">
     Click for your screen resolution </a>

暂无
暂无

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

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