Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
628 views
in Technique[技术] by (71.8m points)

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

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..

Anybody know of a good script to support ALL browsers or at least to come back and tell me its not supported, I have access to jQuery - maybe there is some way to detect the browser

I am currently using this and it works for IE and Firefox but not chrome

if (window.sidebar) { // Mozilla Firefox
    window.sidebar.addPanel(name, url, "");
}
else if (window.external) { // IE
    window.external.AddFavorite(url, name);
}
else if (window.opera && window.print) {
    window.external.AddFavorite(url, name);
}
else {
    alert('not supported');
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Sorry, but there's no cross-browser way to do this. Your FF example is broken as well: It won't create a regular bookmark, but a bookmark set to be opened in the sidebar. You'd have to use the bookmark-service to create an actual bookmark, but this'll fail due to security restrictions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...