I haven't done much research on this yet but I just woke up and wanted to get this down before I forgot.

I need to make a "bookmark this page" sorta thing, buuuuut as we all know the functionality of this in Javascript is sketchy cross-browser wise. I did a quick google search and you can see this is no biggie in IE or Firefox, but what about the rest?

function addBookmark(title, url) {
        if (window.sidebar) { // firefox
              window.sidebar.addPanel(title, url,"");
        } else if( document.all ) { //MSIE
                window.external.AddFavorite( url, title);
        } else {
               alert("Sorry, your browser doesn't support this");
        }
}

So what I was wondering is if there is a way for Javascript to simulate the user pushing a key. Something like this pseudocode:

function addBookmark(){
     if(OS == Mac){
        if(browser == Camino){
           Keyboard.press(COMMAND + K);
        } else {
            Keyboard.press(COMMAND + D);
        }
     } else {
       Keyboard.press(CONTROL + D);
     }
}

Kinda like an interrupt for those of you familiar with assembly.

Maybe this doesn't make sense, like I said I just woke up. Any ideas let me know. Maybe I'm way off and there's a much simpler way.

Thanks
Steve

    No - what that does is it determines the code of the key pressed. I want the user to click a link and when that link is clicked it would be the equivalent of them pressing CONTROL + D, except without actually pressing any keys

      All I know is that I hope it's impossible. I sure don't like the idea that a script running in my browser could simulate keystrokes. (Ctrl-Alt-Del, anyone? :eek🙂

        slindstr No - what that does is it determines the code of the key pressed. I want the user to click a link and when that link is clicked it would be the equivalent of them pressing CONTROL + D, except without actually pressing any keys

        Sorry 'bout that, didn't quite understand your first post...

        EDIT: sorry, I'm real tired, the link of course is basically the same as my first post.

        EDIT 2 - The Return of Edit: I put some noggin into it, and it seems that it is not possible to do this with non-IE browsers. Probably because of the same reasons that worry NogDog...

        NogDog All I know is that I hope it's impossible. I sure don't like the idea that a script running in my browser could simulate keystrokes. (Ctrl-Alt-Del, anyone? )

        I would figure that that the key actions, if possible, would be restricted to the browsers mapping (and thus ctrl+D will invoke "bookmark as" and not some other non-browser program shortcut).* But then again, I'm no expert...

        • Not saying that having a script executing F1 and other browser options wouldn't be quite as scary/annoying.

          I don't think it's possible - if it was then I'm sure that I would be seeing it all over google as the preferred method for bookmarking.

            Write a Reply...