user1265533
user1265533

Reputation: 173

JQUERY: IE9 ignoring PreventDefault

I've search high and low and turned up with no solution.

I am wanting my submit function to handle the action when the user clicks the submitt button, and override the default action.Firefox and Chrome work flawless, but in IE9, clicking the form button results in the page going to Default.aspx(I am using ASP.NET, and running this code on localhost).

/////////////////Submit Function/////////////
 $('#ARBB').submit(function (event) {
     //e.cancelBubble is supported by IE - this will kill the bubbling process.
     event.cancelBubble = true;
     event.returnValue = false;

     //e.stopPropagation works only in Firefox.
     if (event.stopPropagation) {
         event.stopPropagation();
         event.preventDefault();
     }

     // initialize validator for a bunch of input fields
     var inputs = $("#Contact :input").validator();

     // perform validation programmatically
     //inputs.data("validator").checkValidity();

     $('#conf').load("/Confirmation.aspx");

     $.blockUI({ css: {
         border: 'none',
         padding: '15px',
         backgroundColor: '#000',
         '-webkit-border-radius': '10px',
         '-moz-border-radius': '10px',
         opacity: .5,
         color: '#fff'
     }
     });

     setTimeout($.unblockUI, 500);

     $("#accordion").accordion("enable");
     $("#accordion").accordion("option", "active", 3);
     $("#CheckMark3").fadeIn("fast");
     $('html, body').animate({
         scrollTop: $("#Section3").offset().top
     }, 500);

 });
 ///////////////////////////////////////////

EDIT/UPDATE

IE9 is throwing the error when the load function is called:

$('#conf').load("/Confirmation.aspx");

The error is:

SCRIPT5: Access is denied.

jquery-1.6.2.js, line 6244 character 2

Upvotes: 0

Views: 2031

Answers (4)

user1265533
user1265533

Reputation: 173

Apparently, the issue was with some CSS code that appears at the top of the page I am loading(Confirmation.aspx). After deleting the css code, I longer get the access denied error.

Upvotes: 0

Raymond Morphy
Raymond Morphy

Reputation: 2526

preventDefault() just working for fire fox and chrome. try thi code:

if (event.preventDefault) { event.preventDefault(); } else { event.returnValue = false; }

this code checks if browser supports preventDefault uses it else executes second part.

Upvotes: 0

Rajesh
Rajesh

Reputation: 3014

did you tried entering return false at the end of the method?

$('#ARBB').submit(function (event) {
     //e.cancelBubble is supported by IE - this will kill the bubbling process.
     event.cancelBubble = true;
     event.returnValue = false;

     //e.stopPropagation works only in Firefox.
     if (event.stopPropagation) {
         event.stopPropagation();
         event.preventDefault();
     }

     // initialize validator for a bunch of input fields
     var inputs = $("#Contact :input").validator();

     // perform validation programmatically
     //inputs.data("validator").checkValidity();

     $('#conf').load("/Confirmation.aspx");

     $.blockUI({ css: {
         border: 'none',
         padding: '15px',
         backgroundColor: '#000',
         '-webkit-border-radius': '10px',
         '-moz-border-radius': '10px',
         opacity: .5,
         color: '#fff'
     }
     });

     setTimeout($.unblockUI, 500);

     $("#accordion").accordion("enable");
     $("#accordion").accordion("option", "active", 3);
     $("#CheckMark3").fadeIn("fast");
     $('html, body').animate({
         scrollTop: $("#Section3").offset().top
     }, 500);
return false;
 });

Upvotes: 1

Guffa
Guffa

Reputation: 700302

The jQuery library already takes care of the browser differences for you. All you need to handle all different browsers is:

event.preventDefault();

Upvotes: 2

Related Questions