简体   繁体   中英

Confirm Delete Javascript message not getting displayed on 'IE11' and 'Chrome'

I have confirm delete message in my application and it works on IE8-9 but not on 'IE11' and 'Chrome'. I checked all settings and scripts are enabled on both browsers.

When I click on 'delete' link nothing happens page is just refreshed and no message is displayed and record is not deleted.

This is my _delete_from_page.rhtml file in 'views' directory.

<%= render :partial => "layouts/top_menu"%>
<%= render :active_scaffold => "testing_page_chain"%>
<html>
  <head>
      <script language="javascript">
      function doRedirect()
      {
      var confirm_msg=confirm("Are you sure you want to delete the request with ID <%=@d.controller_id%>?" ,"");
      var id=<%=@d.id%>
      if (confirm_msg==true)
        {
        window.location="<%= url_for(:controller => "#{params[:controller]}")%>/confirm_delete?id="+id;
        }
      else
        {
        window.location="<%= url_for(:controller => "#{params[:controller]}")%>/cancel_delete";
        }
      }

  function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
      window.onload = func;
    } else {
      window.onload = function() {
        if (oldonload) {
          oldonload();
        }
        func();
      }
    }
  }
</script>
  </head>
</html>
<script language="javascript" type="text/javascript">
    window.onload=addLoadEvent(doRedirect)
</script>

and I call this from controller 'testing_page_chain_controller.rb' like

render :partial => "delete_from_page"

Why don't you use data-confirm?

<%=link_to 'Delete', url, date: {confirm: 'Are you sure?'} %>

This is in Rails default installation by default. Then you can do your server stuff after they confirm they want to delete the object.

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