简体   繁体   中英

How can I add some content to Chrome/Chromium browsers?

I need to put a "Bookmark us" in my website. But as I searched using Google all the results conclude that no way to do "Bookmark us" for Chrome/Chromium browsers.

So I want to either:

1- Hide the content from chrome/chromium browsers.

or at least,

2- Show a message if the user's browser is chrome/chromium after clicking that buttong.

Here is my "Bookmark Us" script:

    /** Bookmark Us */
    function bookmark_us(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);
    } else {

    }
    /** Bookmark Us */


<a href="javascript:bookmark_us('URL','TITLE')">Bookmark Us!</a>

Just add code to show the message saying that it isn't supported on Chrome / Chromium in the final else

/** Bookmark Us */
function bookmark_us(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);
}


function hide_unsupported(){
    if( !(window.sidebar || (window.opera && window.print) || document.all) ){
        document.getElementById('bookmark').style.display = 'none';
    }
}

window.onload = function (){
    hide_unsupported();
}

<a id='bookmark' href="javascript:bookmark_us('URL','TITLE')">Bookmark Us!</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM