2011-04-15 51 views
1

我正在制作一个类似Google Analytics的应用程序,并希望使用JavaScript查找屏幕分辨率。使用javascript的屏幕分辨率

所有现在可用的分析工具(无论是Google Analytics,Piwik,OWA还是其他)都可以提供屏幕分辨率检测。

我该如何做到以下几点?

编辑:我想你们都出错了。我正在制作类似于Google Analytics的工具

编辑2:如果您熟悉Google Analytics,它会提供跟踪代码(使用JavaScript)。当页面被加载时,脚本执行并且你得到一个命中。

编辑3:我相信社区人士错误地理解了我的问题。我认为这里的每个人都会熟悉Google Analytics代码,但我认为我必须展示GA代码的样子。

编辑4:GA代码下面的样子

<script type="text/javascript"> 

    var _gaq = _gaq || []; 
    _gaq.push(['_setAccount', 'UA-123456789-1']); 
    _gaq.push(['_trackPageview']); 

    (function() { 
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
    })(); 

</script> 
+0

使用'screen.width'和'screen.height'试过吗? – Khez 2011-04-15 08:31:40

+0

重复的1000年... http://stackoverflow.com/questions/2242086/how-to-detect-the-screen-resolution-with-javascript。搜索是你的朋友... – neurino 2011-04-15 08:32:17

+0

只需使用screen.width并将其发送到服务器?阿贾克斯是你的朋友.. – halfdan 2011-04-15 08:35:52

回答

-1

window.screen.widthwindow.screen.height