简体   繁体   中英

Javascript onclick function on div works only in IE

I have this code to call a function on a div when it's clicked:

<div class="buttonsim" runat="server">
  $(document).ready(function () {
    $("div.buttonsim").click(function() {
      window.location.href("sim.aspx");
    });
  });

It works on IE but not on Chrome and Firefox> Am I doing something wrong? Is it missing something?

window.location.href is not a method, it should be

window.location.href = "sim.aspx";

If you really want to use a method, you can use assign()

window.location.assign("sim.aspx");

You need to actually set the window.location.href property as you are currently using it as a method :

    $("div.buttonsim").click(function() {
        window.location.href = "sim.aspx";
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM