ตัวอย่าง
บันทึกหน้านี้ไว้Javascript ฟังก์ชั่น
<script type="text/javascript">
function bookmark(title,url){
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);
}
}
</script>
HTML Code การเรียกใช้งาน
<a href="javascript:bookmark(document.title,window.location);">บันทึกหน้านี้ไว้</a>
<!--
เราสามารถกำหน title และ url ในฟังก์ชั่น เลย เช่น
<a href="javascript:bookmark('javascript bookmark','https://www.ninenik.com');">บันทึกหน้านี้ไว้</a>
หรือกำหนดเป็น
<a href="javascript:bookmark(document.title,window.location);">บันทึกหน้านี้ไว้</a>
โดย document.title จะดึง title ของหน้าเว็บนั้นมาโดยอัตโนมัติ
และ window.location จะดึง url ของหน้าเว็บนั้นมาให้โดยอัตโนมัติ เช่นกัน
-->