2013-01-11 27 views
-1

我有一個按鈕,當它被點擊時它會調用一個獲取瀏覽器大小的警報,但它只是表示undefined x undefined。如果我刪除功能部件,那麼它將正常工作。我如何使它與點擊按鈕一起工作?使用HTML頁面獲取瀏覽器大小

<input type="button" onclick="alertME()" value="Finish"> 

<script> 

function alertME() 
{ 
alert (screen.width + 'x' + screen.height); 
} 

</script> 
+1

您正在使用哪種瀏覽器?以上代碼適用於Chrome和Firefox。 – ram1

+2

檢查http://www.javascripter.net/faq/browserw.htm –

+0

我正在使用firefox – Joe24

回答

0

當您收到未定義的消息時,是否使用firefox打開了該文件?如果是這樣的版本?我知道我的代碼可以正常工作(v17)在舊版本的屏幕中可能不支持。

0

嘗試以下操作:

​​
0

這個固定爲我上的jsfiddle:

var width = screen.width; 
var height = screen.height; 

window.alertME = function() 
{ 
    alert(width + 'x' + height); 
} 

HTML:

<input type="button" onclick="alertME();" value="Finish"> 
0

當你得到undeafsfined消息,ASF沒有你用Firefox打開文件?如果是這樣v​​ersafdsgion?我知道minedadg可以很好地使用此代碼(v17)在舊版本的versiodagadgns屏幕中可能不支持.dfkjngdojsndosgdg