Add to browser favorites/bookmarks from JavaScript but for all browsers (mine doesn't work in Chrome)?

前端 未结 6 1767
时光取名叫无心
时光取名叫无心 2020-11-28 09:38

Can anyone help, I am using the following for adding a bookmark to IE and Firefox but its not working in Chrome and I don\'t get my error msg saying \"not supported\" either

6条回答
  •  执笔经年
    2020-11-28 10:05

    I couldnt get the above example to work. Anyway the answer to the original question 'its not working in CHROME and i don't get my error msg saying "not supported" either..' is due to the line

    else if (window.external) { // IE 
    

    chrome actually passes this test and then obiously fails to add a bookmark. I changed this line to

    else if(window.external && !window.chrome)  // IE
    

    and now you get the 'not supported' message. I actually removed this message and called the function hotKeys() to get a more meaningful alert. I had to make a few changes to get that to work

    function showHotKeys() 
    { 
    var ua = navigator.userAgent.toLowerCase(); 
    var str = ''; 
    var isWebkit = (ua.indexOf('webkit') != - 1); 
    var isMac = (ua.indexOf('mac') != - 1); 
    
    if (ua.indexOf('konqueror') != - 1) { 
        str = 'CTRL + B'; // Konqueror 
    } else if (window.home || isWebkit || isMac) { 
        str = (isMac ? 'Command/Cmd' : 'CTRL') + ' + D'; // Netscape, Safari, iCab
    } 
    return ((str) ? 'Press ' + str + ' to bookmark this page.' : str); 
    } 
    

提交回复
热议问题