Running a JavaScript code when a browser bookmark is clicked

Posted by Arjun Vasudevan on Stack Overflow See other posts from Stack Overflow or by Arjun Vasudevan
Published on 2010-06-03T13:12:47Z Indexed on 2010/06/03 13:14 UTC
Read the original article Hit count: 268

Filed under:
|
|
|

I've written a code that has successfully created a bookmark for any of the following browsers - IE, Firefox and Opera.



        function bookmark() 
        {
            var title = 'Google';
            var url = 'http://google.com';

            if (document.all)// Check if the browser is Internet Explorer
                window.external.AddFavorite(url, title);

            else if (window.sidebar) //If the given browser is Mozilla Firefox
                window.sidebar.addPanel(title, url, "");

            else if (window.opera && window.print) //If the given browser is Opera
            {
                var bookmark_element = document.createElement('a');
                bookmark_element.setAttribute('href', url);
                bookmark_element.setAttribute('title', title);
                bookmark_element.setAttribute('rel', 'sidebar');
                bookmark_element.click();
            }
        }


Now I want my bookmark to run a piece of JavaScript code instead of surfing to Google, when the user clicks on it.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about click