页面抛出JavaScript运行时错误:“函数名称”未定义。仅限IE10

时间:2021-08-01 04:17:07

While working on IE10, I have found that the JavaScript functions which are registered or called from the code behind are throwing exception:

在使用IE10时,我发现从后面的代码注册或调用的JavaScript函数抛出异常:

"JavaScript runtime error: 'function name' is undefined".

“JavaScript运行时错误:'函数名'未定义'。

For ex: Code behind in the (!IsPostBack) block:

例如:(!IsPostBack)块后面的代码:

Page.RegisterStartupScript("showGCAlert", "<script language=\"javascript\">ShowGCAlert();</script>");

PageView:

页面预览:

function ShowGCAlert()
    {

        alert('GCAlert');
        if(document.getElementById('hdnGCAlert').value != "1")
        {
            document.getElementById('divGCAlert').style.display = "Block";
            document.getElementById('chkReminder').focus();
            document.getElementById('btnLogin').disabled = true;
            document.getElementById('Button2').disabled = true;             

        }
        else
        {
            document.getElementById('divGCAlert').style.display = "none";
            document.getElementById('btnLogin').disabled = false;
            document.getElementById('Button2').disabled = false;                
            if (document.getElementById("txtUsername").value != "")
                document.getElementById("txtPassword").focus();
            else
                document.getElementById("txtUsername").focus();
        }

    }

When the page loads its throws the exception even though the ShowGCAlert() exists on the dynamic page.

当页面加载它时,即使动态页面上存在ShowGCAlert(),也会抛出异常。

After continuing the exception design page shows:

继续异常设计页面显示:

<script language="javascript" src="/ABC/DEF/Scripts/Common.js"></script>
<script language="javascript">
    document.body.style.overflowY="hidden";
    document.body.style.overflowX="hidden";
    var jsAppName ='ABC';
</script>
<script language="javascript">
    function window.onresize() 
    { 
        document.cookie = "resX=" 
                        + document.body.clientWidth 
                        + ";resY=" 
                        + document.body.clientHeight 
                        + ";path=/"; 
    } 
    window.onresize();
</script>
<script type="javascript">
      ShowGCAlert();
</script>
<script language="javascript">
    document.getElementById('txtPassword').focus();
</script>

In ie9 or IE10 compatibility view its working fine. Please show me where i am doing wrong.

在ie9或IE10兼容性视图中它的工作正常。请告诉我我在哪里做错了。

1 个解决方案

#1


1  

Try placing the script at the end of the page using RegisterClientScriptBlock and call it.

尝试使用RegisterClientScriptBlock将脚本放在页面的末尾并调用它。

   Page.ClientScript.RegisterClientScriptBlock("showGCAlert", 
     "<script type=\"text/javascript\">ShowGCAlert();</script>");

#1


1  

Try placing the script at the end of the page using RegisterClientScriptBlock and call it.

尝试使用RegisterClientScriptBlock将脚本放在页面的末尾并调用它。

   Page.ClientScript.RegisterClientScriptBlock("showGCAlert", 
     "<script type=\"text/javascript\">ShowGCAlert();</script>");