overwrite the preventDefault() in another method
I have a this call
<a onclick="facebookLogin();" class="facebook_btn_homepage" href="/signup">
<img src="/images/facebook_btn2.png?1280194712" alt="Facebook_btn2"></a>
$('.facebook_btn_homepage').click(function(event){
event.preventDefault();
});
but in the function facebookLogin() i want to overwrite the
function facebookLogin() {
FB.login(function(response) {
//i want to overwrite the preventDefault and go to another
//page because开发者_高级运维 its trying to go to another url and the preventDefault
//is stopping the page from going to another url
You can call preventDefault()
, then set the window.location
manually when you need to.
$('.facebook_btn_homepage').click(function(event){
event.preventDefault();
// do some stuff
// then manually go to the next page
window.location.href = this.href;
});
Why do you use both the onclick
attribute and jQuery's click event handler?
If you remove the onclick
call to facebookLogin()
and put that in the jQuery click handler, you could decide in the facebookLogin() function whether or not you even need to prevent the default action (going to the URL specified in the href
).
Or am I missing something?
精彩评论