Javascript bookmark - how to check if user clicked OK or Cancel?

Discussion in 'JavaScript' started by Chuckun, Dec 19, 2012.

  1. #1
    I'm developing a bookmark/favourite incentive script and currently the user is awarded even if they click 'cancel' in the add-bookmark dialogue box..

    Is there any way to catch some sort of call back result from the browser to see if the bookmark dialogue was confirmed or cancelled?

    Thanks for any help!

    Chuck
     
    Chuckun, Dec 19, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    
    if(window.confirm("[I]sometext[/I]")) {
       //user clicked OK
    } else {
       //user clicked cancel
    }
    
    Code (markup):
     
    Rukbat, Dec 20, 2012 IP
  3. Chuckun

    Chuckun Well-Known Member

    Messages:
    1,161
    Likes Received:
    60
    Best Answers:
    2
    Trophy Points:
    150
    #3
    Thanks for trying to help Rukbat, but I'm looking for a solution to know whether the user clicked OK or Cancel in the bookmark dialogue box.. Not a standard Ok/Cancel confirm() window..

    Is there any way?
     
    Chuckun, Dec 23, 2012 IP
  4. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #4
    You mean when the user starts to bookmark your site?
     
    Rukbat, Dec 23, 2012 IP
  5. Chuckun

    Chuckun Well-Known Member

    Messages:
    1,161
    Likes Received:
    60
    Best Answers:
    2
    Trophy Points:
    150
    #5
    Yeah.. I have a simple bookmark function I use in a link.. ie:

    <a href="#" onclick="AddBookmark(); return false;">Bookmark us and earn 50 points!</a>
    Code (markup):
    The Bookmark() function currently awards points after the standard bookmark function has been carried out.. ie, the script opens the bookmark dialogue (similar to if they had pressed CTRL+D), and on completion of that dialogue, the script then awards 50 points to their account..

    Code snippet:

    function AddBookmark(url,title) {
    	if (window.sidebar){ // firefox
    		window.sidebar.addPanel(title, url, "");
    	} else if(window.opera && window.print){ // opera
    		var elem = document.createElement('a');
    		elem.setAttribute('href',url);
    		elem.setAttribute('title',title);
    		elem.setAttribute('rel','sidebar');
    		elem.click();
    	} else if(document.all){ // ie
    		window.external.AddFavorite(url, title);
    	}
    	AwardPoints(50);
    }
    ...
    Code (markup):
    However, even if you CANCEL the bookmark dialogue, points are still awarded.. Because I haven't put the AwardPoints() function in any sort of 'if' statement.. What I'm looking for is a result I can retrieve from the bookmark dialogue or some sort of trigger to award the points, rather than just assuming they clicked OK in the bookmark dialogue.

    Chuck
     
    Chuckun, Dec 23, 2012 IP
  6. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #6
    From everything I can determine, the bookmark function doesn't return anything in any of the main browsers. It's not written to be used as an "if bookmark added" function.
     
    Rukbat, Dec 23, 2012 IP
    Chuckun likes this.
  7. Chuckun

    Chuckun Well-Known Member

    Messages:
    1,161
    Likes Received:
    60
    Best Answers:
    2
    Trophy Points:
    150
    #7
    Damn :( Ok nevermind.. It's a one-time function anyway so it can't be 'abused', but it would've been nice to be able to make sure they DID add the bookmark - but at the end of the day, if they wanted to falsify it, they could just delete the bookmark afterwards anyway :p

    Thanks for your efforts Rukbat!
     
    Chuckun, Dec 26, 2012 IP