我正在尝试在内容页面(引用母版页)中使用javascript方法来获取当前屏幕尺寸,并将其写入标签。
到目前为止,我没有运气。我尝试在master和content页面中都这样做,但该方法根本不起作用。有人可以为此提供解决方案吗?
母版:
<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>
答案 0 :(得分:1)
你好你可以尝试用这些行,你具体的情况是第三个(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
答案 1 :(得分:0)
您是否尝试过关注?
<a href="javascript:alert
('Your resolution is ' + screen.width + 'x' + screen.height);">
Click for your screen resolution </a>