Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go to link on click OK #168

Closed
voodoo6 opened this issue Oct 28, 2014 · 4 comments
Closed

Go to link on click OK #168

voodoo6 opened this issue Oct 28, 2014 · 4 comments

Comments

@voodoo6
Copy link

voodoo6 commented Oct 28, 2014

Forgive my inexperience. How can I achieve this:

I'd like sweetalert to show a message when a user clicks a link, but then to only go to the link if the user selects 'OK' in the sweetalert dialog.

Thanks!

@jupazave
Copy link

The library do not have the option to do that. I modify the constructor in #165 (We need to wait to be approved) for sending an extra param to the constroctor, in this case it will be the link.

@t4t5
Copy link
Owner

t4t5 commented Oct 29, 2014

This is actually very simple to achieve. I'm using jQuery in this example.

$('a').click(function(e){
    e.preventDefault();
    var link = $(this).attr('href');

    swal({
        title: "Are you sure?",
        text: "By clicking 'OK' you will be redirected to the link.",
        type: "warning",
        showCancelButton: true
    },
    function(){
        window.location.href = link;
    });
});

This will add the behaviour to all a-tags. If you want it for certain links only, you could add a specific class to the a-tags, and limit the sweetAlert functionality to just them.

@voodoo6
Copy link
Author

voodoo6 commented Oct 30, 2014

Thanks for you help Tristan, that works perfectly!

@mojtabaRKS
Copy link

it's not working!

Uncaught SweetAlert: Unexpected 2nd argument (function(){
window.location.href = mainURL;
});

what should i do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants