當某個按鈕被點擊時,是否有方法將當前頁面保存爲書籤(通過jQuery或其他方式)?使用jQuery點擊書籤
回答
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("a.jQueryBookmark").click(function(e){
e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
var bookmarkUrl = this.href;
var bookmarkTitle = this.title;
if (window.sidebar) { // For Mozilla Firefox Bookmark
window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
} else if(window.external || document.all) { // For IE Favorite
window.external.AddFavorite(bookmarkUrl, bookmarkTitle);
} else if(window.opera) { // For Opera Browsers
$("a.jQueryBookmark").attr("href",bookmarkUrl);
$("a.jQueryBookmark").attr("title",bookmarkTitle);
$("a.jQueryBookmark").attr("rel","sidebar");
} else { // for other browsers which does not support
alert('Your browser does not support this bookmark action');
return false;
}
});
});
</script>
本規範從Developersnippets上當受騙!
/E:
Chrome不支持這樣的行動,因爲安全級別可能被打破。
我如何才能在Chrome中使用它?在Chrome中,警報消息甚至不顯示... – 585connor 2011-04-29 07:17:19
爲了防止在Chrome中拋出錯誤,您應該使用'else if(window.external && window.external.AddFavorite)',因爲'window.external'在Chrome中定義了,但不是'window.external.AddFavorite'。 – 2013-05-14 08:45:14
試試這個:
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);
}
我覺得jquery書籤插件是你在找什麼。 jBrowserBookmark允許你添加功能到一個網站,允許一個頁面被添加到瀏覽器boookmark列表。此功能由Internet Explorer,Firefox,Opera和Konqueror瀏覽器支持。您可以得到它here
由於Chrome不支持此操作,因此解決方案可能首先檢查瀏覽器是否使用Chrome瀏覽器,如果是,提醒用戶書籤功能不受支持。那麼對於其他情況,DevelopersSnippets上提供的腳本工作正常。
例子:
$("a.bookmark").click(function(e){
e.preventDefault(); // this will prevent the anchor tag from going the user off to the link
var bookmarkUrl = this.href;
var bookmarkTitle = this.title;
if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
alert("This function is not available in Google Chrome. Click the star symbol at the end of the address-bar or hit Ctrl-D (Command+D for Macs) to create a bookmark.");
}else if (window.sidebar) { // For Mozilla Firefox Bookmark
window.sidebar.addPanel(bookmarkTitle, bookmarkUrl,"");
} else if(window.external || document.all) { // For IE Favorite
window.external.AddFavorite(bookmarkUrl, bookmarkTitle);
} else if(window.opera) { // For Opera Browsers
$("a.bookmark").attr("href",bookmarkUrl);
$("a.bookmark").attr("title",bookmarkTitle);
$("a.bookmark").attr("rel","sidebar");
} else { // for other browsers which does not support
alert('Your browser does not support this bookmark action');
return false;
}
});
在自己的瀏覽器
- 1. 書籤 - 點擊右鍵?
- 2. Gmail之星使用jQuery書籤書籤
- 3. 我可以使用SSL證書來點擊代碼簽名嗎?
- 4. 錨標籤jQuery的點擊
- 5. 使用jQuery點擊更新DIV點擊
- 6. 使用書籤
- 7. 使用書籤
- 8. 在jQuery中使用書籤地址
- 9. jQuery單擊標籤時點擊兩次點擊
- 10. 使Javascript書籤在特定條件下點擊一個按鈕
- 11. 使用jQuery檢測即使在href標籤上的點擊
- 12. 使用JQuery的DIV點擊
- 13. 使用jQuery連續點擊
- 14. 上點擊它使用jQuery
- 15. jquery使用變量點擊
- 16. jQuery準備書籤
- 17. 製作<cite>標籤可點擊使用jQuery
- 18. 使用懸停並點擊jQuery UI標籤?
- 19. 使用jQuery獲取點擊標籤的文本
- 20. 如何使用jQuery或mootools觸發本機(href)點擊標籤?
- 21. 如何使用jQuery小部件刪除點擊LI標籤?
- 22. jQuery的Fancyform和IE10:標籤上點擊
- 23. jQuery - 點擊標籤時更改圖片
- 24. 點擊加載jquery標籤內容
- 25. 點擊#標籤
- 26. jQuery禁用點擊
- 27. 用jquery點擊GEvent.addListener
- 28. 黑客:禁用點擊與jQuery點擊
- 29. djangobyexample書-jquery書籤不工作
- 30. 使用多個證書籤署證書
?或到一些社交媒體網絡? – wegginho 2011-04-29 07:05:48
在瀏覽器中。 – 585connor 2011-04-29 07:12:07