jquery confirm promt question

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
cardi777
Forum Commoner
Posts: 54
Joined: Sun Mar 29, 2009 4:26 am

jquery confirm promt question

Post by cardi777 »

I found this great script online that does confirm prompts on hrefs. But the href is hardcoded into the js file.

I am trying to make the href get taken from the link itself since...

html...

Code: Select all

<a href='#1' class='confirm'>Demo</a>
js...

Code: Select all

$(document).ready(function () {
    $('#confirm-dialog input.confirm, #confirm-dialog a.confirm').click(function (e) {
        e.preventDefault();
 
        // example of calling the confirm function
        // you must use a callback function to perform the "yes" action
        confirm("Continue to the SimpleModal Project page?", function () {
            [b]window.location.href = 'http://www.ericmmartin.com/projects/simplemodal/';[/b]
        });
    });
});
 
function confirm(message, callback) {
    $('#confirm').modal({
        closeHTML:"<a href='#' title='Close' class='modal-close'>x</a>",
        position: ["20%",],
        overlayId:'confirm-overlay',
        containerId:'confirm-container', 
        onShow: function (dialog) {
            $('.message', dialog.data[0]).append(message);
 
            // if the user clicks "yes"
            $('.yes', dialog.data[0]).click(function () {
                // call the callback
                if ($.isFunction(callback)) {
                    callback.apply();
                }
                // close the dialog
                $.modal.close();
            });
        }
    });
}
 
I want the js file to grab the href from the comfirm link and us that as the href...

Code: Select all

window.location.href = [b]href-on-html-link-here[/b];
Is this something that can be done ?

Any help would be appreciated!

Cheers,
Doug
cardi777
Forum Commoner
Posts: 54
Joined: Sun Mar 29, 2009 4:26 am

Re: jquery confirm promt question

Post by cardi777 »

ah i almost figured it out...

Code: Select all

window.location.href = $("a").attr("href");
Last edited by cardi777 on Thu Sep 10, 2009 12:33 am, edited 1 time in total.
cardi777
Forum Commoner
Posts: 54
Joined: Sun Mar 29, 2009 4:26 am

Re: jquery confirm promt question

Post by cardi777 »

ahhh no that doesn't work.. if you have multiple links, it just uses the first href every time! help!
cardi777
Forum Commoner
Posts: 54
Joined: Sun Mar 29, 2009 4:26 am

Re: jquery confirm promt question

Post by cardi777 »

forget it... found this instead...

http://abeautifulsite.net/notebook/87
Post Reply