2012-08-06 87 views
0

我試圖在內容頁面(引用母版頁)中使用JavaScript方法來獲取當前屏幕尺寸,並將其寫入標籤。在內容頁面中使用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> 
+0

你是怎麼做到的?我的意思是你的代碼不工作? – codingbiz 2012-08-06 12:46:21

+0

請顯示您的代碼,並告訴我們您使用的是什麼網頁瀏覽器。 – funerr 2012-08-06 12:47:18

+0

添加了代碼。道歉.. – TheGeekZn 2012-08-06 13:03:55

回答

0

有無你試過了嗎?

<a href="javascript:alert 
    ('Your resolution is ' + screen.width + 'x' + screen.height);"> 
    Click for your screen resolution </a> 
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 
+0

我所做的每一次嘗試都會將代碼顯示爲頁面頂部的純文本,或者根本不顯示。 – TheGeekZn 2012-08-06 13:48:36

+0

我確定你有css問題(樣式表),但沒有這個腳本 – 2012-08-06 13:51:19

+0

我唯一的其他腳本是CCS腳本,它改變基於瀏覽器的樣式表... – TheGeekZn 2012-08-06 13:58:35