按钮点击不触发Chrome中的javascript功能,但在IE中工作正常

时间:2016-08-03 05:45:41

标签: javascript html google-chrome internet-explorer

按钮点击不会在Chrome中触发javascript函数(InsertRecord()),但在IE中工作正常。

<input id="submit" type="button" value="Request Access" onclick="InsertRecord()" style="width:160px;"/>


function InsertRecord()
    {
        var txtUserName = document.getElementById('txtUserName').value;
        var txtDept = document.getElementById('ddlDept').value;
        var txtClass = document.getElementById('txtClass').value;
        var txtRole = document.getElementById('ddlRole').value;
        var txtAccess = document.getElementById('ddlAccess').value;
        if (txtUserName.length != 0 || txtDept.length != 0 || txtClass.length !=0 || txtRole.length !=0 || txtAccess.length !=0)
        {
            var connection = new ActiveXObject("ADODB.Connection");
            var connectionstring = "Data Source=dvuksdcwsql001;Initial Catalog=RP_5500_AppDB;Persist Security Info=True;User ID=CPT_DEV;Password=Cpt%100@123;Provider=SQLOLEDB";
            connection.Open(connectionstring);
            var rs = new ActiveXObject("ADODB.Recordset");
            rs.Open("insert into Range_Plan_Access values('" + txtUserName + "','" + txtDept + "','" + txtClass + "','" + txtRole + "','" + txtAccess + "')", connection);
            alert("Access Requested Successfully!");            

            connection.close();
        }
        else
        {
            alert("Please enter a value for User Name \n Department \n Class \n Role \n Access Required!");
        }
    }  

请你告诉我这个问题吗?

谢谢,

3 个答案:

答案 0 :(得分:1)

问题在于ActiveXObject()调用,因为它们仅在IE中受支持。 Chrome使用另一种名为NPAPI的插件架构。有一个跨浏览器插件框架Firebreath,可能对您有用。

更新稍微搜索一下后,我还在Google Chrome帮助论坛上找到了this discussion,其中指出IE Tab for Google Chrome可能允许您的现有代码正常运行。试一试!

答案 1 :(得分:1)

仅在IE中支持ActiveX。

我认为你必须避免这种用途,因为你在客户端暴露你的数据库,所以任何人都可以操纵你的数据库。

这是我的观点。避免使用ActiveX来完成这项工作。

创建一个Web服务来完成这项工作。

希望对你有所帮助。

答案 2 :(得分:0)

Chrome不支持ActiveX。您不应该通过浏览器连接到数据库,您应该有一个连接到数据库的服务器端API。你要做的就是糟糕的mkay!