<script language="javascript">
res = "&res="+screen.width+"x"+screen.height+"&d="+screen.colorDepth
top.location.href="Login.aspx?action=set"+res
</script>
Source Error:
An unhandled exception was generated during the execution of the current web request,Information regarding origin and location exception can be identified using the exception stact trace below.
Stack trace:
[Null ReferenceException: object reference not set to an instance of an object.]
page_Load(object sender EventArgs e)+143
and next from System.Web
根据屏幕分辨率设置登录网页。如何避免空引用异常?
您可能应该考虑使用自动调整的基于流的页面布局。但是,我过去也做过类似的事情,诀窍是将大小调整代码放在超时中:
setTimeout(function() {
res = "&res="+screen.width+"x"+screen.height+"&d="+screen.colorDepth
top.location.href="Login.aspx?action=set"+res
}, 0);
这是必需的,因为脚本代码不确定地执行。有时它会在计算和填充屏幕尺寸之前运行。其他Ajax工具包(如jQuery)通过将页面初始化代码放在一个特殊的onLoad处理程序中来处理这个问题。