Using PreventDefault()
Aug 30, 2005
he scenario is that I want to add on onclick handler to a link. When
the onclick handler fires, I want action A to take place, which will
be a request. I want to insure that action A completes before the
click to the link retrieves the page. To do that, I would like to
issue a preventDefault(), wait for action A to complete and then
direct the browser to the page specified in the link (e.g., set
location.href="clicked_link_ref").
I just cannot find any practical information that leads me to a way to
do this. I have googled and read the O'Reilly book on JS and the JS
cookbook, as well. I haven't been able to backtrack from their
examples to a solution to my own problem.
View 3 Replies
Apr 20, 2006
In the following script:
function txKeyPressHandler(theEvent) {
var key = theEvent.which || theEvent.keyCode;
switch (key) {
case Event.KEY_RETURN:
txIMSendMsg();
var userAgent = window.navigator.userAgent;
if (userAgent.indexOf('MSIE 6.0') == -1) theEvent.preventDefault();
break;
}}
if I take out the if clause, forcing the preventDefault to get called even
for IE6 it causes a JS error (just in IE6).
View 4 Replies
View Related
Apr 22, 2011
$(".change_page").click(function(e){
e.preventDefault();
do_stuff();
});
I noticed when I click one of these links, there is an ever so slight lag on all browsers. Maybe less than half a second, but it'snoticeable.
Now, when I remove e.preventDefault() and use return false instead, everything runs a lot smoother.
View 1 Replies
View Related
Apr 7, 2010
jquery-1.4.2.min.js
I'm trying to use the Alt+keyCode in my web-app and want to prevent the event from bubbling up to the browser.
The following works fine in FF & Chrome, no event propagation, but fails in IE8:
$().ready(function() {
$('html').keydown(function(event) {
if (event.altKey) {
if (event.altKey && event.keyCode == 83) { // 'S'
[Code].....
View 3 Replies
View Related
Sep 4, 2006
The Yahoo! UI event library goes to extremely great lengths to solve
this problem. Their solution is very creative but uses browser
sniffing. In Safari 1.3 (and earlier?) the following example follows
the link when it should not. Does anyone know of any solutions without
browser sniffing?
<p><a id="one" href="http://www.yahoo.com">link cancelled with
e.preventDefault()</a(isn't cancelled in Safari 1.3, is cancelled in
Safari 2)</p>
<script type="text/javascript" charset="utf-8">
document.getElementById('one').addEventListener('c lick',
function(e){e.preventDefault();}, false);
</script>
View 1 Replies
View Related
Apr 30, 2010
I have this function which prevent the default envent of a link. So far is ok. Then the function execute some tasks and then I need TO CONTINUE with the event with something like event.continueDefault(); Can I do this?
Something like:
$('.link').live('click', function(event) {
event.preventDefault(); // STOP THE EVENT
...//EXECUTE SOME TASKS
event.continueDefault() // LET THE EVENT CONTINUE. Of course, this line doesn't work.
});
View 2 Replies
View Related
Jul 17, 2009
I'm using IE8 and when I pass: event.preventDefault(); I get an error
message:
Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/
4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR
3.0.30729; .NET CLR 3.5.30729)
Timestamp: Fri, 17 Jul 2009 20:07:41 UTC
Message: Object doesn't support this property or method
Line: 256
Char: 3
View 6 Replies
View Related
Sep 10, 2010
I know the title is not so good, it's hard to explain the simply thing I'd like to do.In fact, I'm looking for a reverse e.preventDefault() method, something like that :
$(document).keydown(function (e){
if ( e.keyCode == 9)
{
[code]....
View 5 Replies
View Related
Mar 24, 2011
I am checking if a form on a jQuery tab is changed, and if it has, the user should get a popup warning when they navigate away from the tab with the form or click any other link on the page for that matter. So I setup this code:
$('a').bind('click', function(event) {
if (formChanged == true) {
event.preventDefault()
[code]....
in the $(document).ready() function. I can see the code is executed, but the click on the link still comes through and the form is lost. I've tried .click() and .live('click') as well but that doesn't work either.
View 2 Replies
View Related
Oct 22, 2009
I want create a page which has animation at the bottom of that page. I use jQuery to do that. This is the way I do it
<a href="#" class="animation">Animate this</a>
And this is the jquery
$(document).ready(function() {
$('a.animation').click(function(e) {
e.preventDefault();
//animation goes here;
});
});
When I run the code, all animation run very well except the page always scroll to the top. I try to change the href attribute to javascript:void(0); but it still run like that..
View 5 Replies
View Related
Jul 12, 2010
Has anybody used <button type="submit" name="dil" value="bert">dilbert</button> and attempted to add submit validation through the submit handler and preventDefault() only to find out the element value is missing? I'm currently experiencing this problem and it's a real headache.
View 4 Replies
View Related
Aug 13, 2011
look at this script :
$(function(){
$('input').bind('keypress',null,b).bind('change',null,a);
});
function a(){
[Code].....
this script bind both keypress and change of the text box to functions b and a. at keypress event handler if user type a char on input box the value of input box change to x and the user char discarded. In this case we expected to run the onchange (change) event because the textbox value is changed BUT this doesn't happen.
View 1 Replies
View Related