简体   繁体   English

OnClick功能在IE 10中不起作用,但在较早版本中可以使用

[英]OnClick function is not working in IE 10, but fine in older versions

Within a standard Dot.Net application there is an option to add buttons, which can do certain functions. 在标准的Dot.Net应用程序中,有一个添加按钮的选项,该按钮可以执行某些功能。

This button, when clicked, opens Google in a new window with an input parameter from the current window. 单击此按钮后,将在新窗口中打开Goog​​le,其中包含当前窗口中的输入参数。

<button class="exButton" language="VBS" onclick="MakeReq()">Search Google</button>
&nbsp;
<script language="VBS"> 
    Sub MakeReq() 
        window.open "https://www.google.nl/?gws_rd=ssl#q=" & frmMain.FreeTextField_01.Value 
    End Sub
</script>

The button works fine in IE9 or in IE10 in compatibility mode. 在兼容模式下,该按钮在IE9或IE10中可以正常工作。 However on Chrome or IE 10 it does not function. 但是,在Chrome或IE 10上它不起作用。 I get no response or visible error. 我没有响应或可见错误。

Does anyone know: 有人知道吗:

  1. Why it fails to function in IE10? 为什么它无法在IE10中运行?
  2. More importantly how I can adjust to code to get it working again? 更重要的是,如何调整代码以使其再次正常工作?

Please keep in mind I can only influence this small piece of script as the rest of the page is controlled by the supplier of the application. 请记住,由于页面的其余部分由应用程序的供应商控制,因此我只能影响这一小段脚本。

Move to javascript, something like this: 转到javascript,如下所示:

<button class="exButton" onclick="MakeReq()">Search Google</button>
&nbsp;
<script language="text/javascript"> 
    function MakeReq() {

        frmMain = document.forms[0]; // if it is the first form
        textField = frmMain.elements["FreeTextField_01"];

        window.open("https://www.google.nl/?gws_rd=ssl#q="+textField.value;
    }
</script>

But it's not cleat what is frmMain.FreeTextField_01.value, so I tried to imagine it is a field in the first form in the page. 但这不是什么是frmMain.FreeTextField_01.value,因此我试图想象它是页面中第一种形式的字段。

Other ways could be: 其他方式可能是:

textField = document.getElementsByName("FreeTextField_01")[0];

or 要么

frmMain = document.forms["frmMain"];
textField = frmMain.elements["FreeTextField_01"];

or 要么

frmMain = document.forms[0]; // if it is the first form
textField = frmMain.elements[0]; // if it is the first form element

or 要么

frmMain = document.getElementById("frmMain");
textField = frmMain.elements["FreeTextField_01"];

if the form has an id="frmMain" 如果表单具有id =“ frmMain”

Thanks for the help! 谢谢您的帮助! Below is what ended up working for me. 以下是最终为我工作的内容。

 <button class="exButton" onclick="myFunction()">Google Search</button> 
 <script language="text/javascript"> 
       function myFunction() 
          { 
           frmMain = document.getElementById("frmMain"); 
           textField = frmMain.elements["FreeTextField_01"]; 

           window.open("google.nl/?gws_rd=ssl#q="+textField.value); 
          } 
</script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Javascript Array在IE7和更早版本中不起作用,但在IE10中起作用 - Javascript Array not working in IE7 and older versions but working in IE10 onclick 功能在 IE 中不起作用,但在其他浏览器上工作正常 - The onclick function is not working in IE but works fine on other browsers onclick事件在firefox中不起作用,但在IE中可以正常工作 - onclick event not working in firefox but works fine in IE Cordova “Origin: file://”-错误使用和 Android 10,旧版本工作 - Cordova “Origin: file://”-Error using and Android 10, older versions working Lightbox2中的导航在旧版IE版本(IE10及更低版本)上无法正常运行 - Navigation in a Lightbox2 doesn't work well on older IE versions (IE10 and lower) IE较旧版本上的jQuery问题 - Jquery issues on older versions of IE onclick 函数在 IE 中返回 undefined,在 Chrome 和 Firefox 中工作正常 - onclick function returns undefined in IE, works fine in Chrome and Firefox JS函数与firefox和IE一起正常工作,但不能用chrome - JS function working fine with firefox and IE, but not with chrome Function 在 Chrome 和 IE 中工作正常,但在 FireFox 中不能正常工作 - Function working fine in Chrome and IE but not in FireFox jQuery在IE 9或更旧版本中不起作用 - Jquery not working in IE 9 or older
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM