[英]Get page dimensions using JavaScript in a Content Page
I am trying to use a javascript method in a content page (Referencing master page) to get the current screen dimensions, and write it to a label. 我正在尝试在内容页面(参考母版页)中使用javascript方法来获取当前屏幕尺寸,并将其写入标签。
So far, I have had no luck. 到目前为止,我还没有运气。 I tried doing it in both the master, and content page, but the method is simply not working. 我尝试在母版页和内容页中都这样做,但是该方法根本无法正常工作。
Could someone please provide the solution for this? 有人可以为此提供解决方案吗?
MasterPage: 母版页:
<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 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>
Hello you can try with theses lines, you specific case is the third (clientHeight and clientWidth) 您好,您可以尝试使用这些代码行,您的具体情况是第三个(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
Have you tried following? 您是否尝试过追踪?
<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.