希望解決Opera 10加入書籤的功能,在網路上找到這個範例,我也試著把這個套用這個範例的作法,但遇到了不能正常Work的問題。
function addBookmark(title, url, obj){
if (!url) url = location.href;
if (!title) title = document.title;
if ((typeof window.sidebar == "object") &&
(typeof window.sidebar.addPanel == "function"))
window.sidebar.addPanel (title, url, "");//Gecko
else if (document.all)
window.external.AddFavorite(url, title); //IE4+
else if (window.opera && document.createElement) {
obj.setAttribute('rel','sidebar');
obj.setAttribute('href',url);
obj.setAttribute('title',title);
}
else {
alert("Your browser does not support bookmarks
Press ctrl+D (ctrl+T for old Opera);");
return false; //IF Opera 6
}
return true;
}
<a href="#" onclick="addBookmark('google','http://google.com', this);"> Bookmark us! </a>範例來自: http://stackoverflow.com/questions/1542696/bookmark-function-opera-9-10
後來我在觸發的時候,的Link的寫法是
<a href ="addBookmarkForBrowser('ASUS bookmark', this);">Add to Favorites</a>
發現不管我怎麼用,就是沒辦法正常加入,後來發現,原來觸發的時候,必須使用onclick這樣的方式,才能夠正常加入書籤,至於原因為何,我到現在也還不是清楚,需要再研究。
<a href="#"" onclick="addBookmarkForBrowser('ASUS bookmark', this);">Asus Bookmark</a>
以下是我修改完後,相關的程式片段
<html>
<script>
function addBookmarkForBrowser(sTitle, obj) {
sTitle = sTitle+" - ";
if (document.all){
window.external.addFavorite('http://19.168.1.1', sTitle);
}
else if (window.sidebar && window.sidebar.addPanel){
window.sidebar.addPanel(sTitle, 'http://192.168.1.1', "");
}
else if (window.opera && document.createElement) {
obj.setAttribute('rel','sidebar');
obj.setAttribute('href', 'http://192.168.1.1');
obj.setAttribute('title', 'ASUS');
}
else {
addBookmarkForBrowser = function() {
alert("<#Browser_action_not_support_addfavorite#>");
}
}
return true;
}
</script>
<body>
<a href="#"" onclick="addBookmarkForBrowser('ASUS bookmark', this);">Asus Bookmark</a>