Getting Href value in jquery

If you click Members or Shop in the main navigation you will be asked if you are sure you want to leave the site.

I put this in via functions.php using the jquery below,

<script>
jQuery(function() {
function leave_now(event) {
var choice = window.confirm( 'You are now leaving Tumble Tots, do you wish to continue?' );
return choice;
}

var select_external = 'a[href*="//"]:not([href*="allanlove.net"])';
jQuery(document).on( 'click', select_external, leave_now )
});
</script>

Where it says “You are now leaving Tumble Tots, do you wish to continue?” I need it to say “You are now leaving Tumble Tots to go to (Link of page eg http://tumbletotsmemberoffers.com/) do you wish to continue?”

But I am unsure how to get the href link in the jquery?

I look forward to you response,

Regards

  • Adam
    • Support Gorilla

    Hello allanlove

    I hope you’re well today!

    All you’d need to do would be to replace this line in your script

    var choice = window.confirm( 'You are now leaving Tumble Tots, do you wish to continue?' );

    with this code

    var addressValue = $(this).attr("href");
    var choice = window.confirm( 'You are now leaving Tumble Tots to go to ' + addressValue + ', do you wish to continue?' );

    I hope that helps :slight_smile:

    Best regards,

    Adam