admin管理员组文章数量:1279042
I've written a code that has successfully created a bookmark for any of the following browsers - IE, Firefox and Opera.
<script language="JavaScript" type="text/javascript">
function bookmark()
{
var title = 'Google';
var url = '';
if (document.all)// Check if the browser is Internet Explorer
window.external.AddFavorite(url, title);
else if (window.sidebar) //If the given browser is Mozilla Firefox
window.sidebar.addPanel(title, url, "");
else if (window.opera && window.print) //If the given browser is Opera
{
var bookmark_element = document.createElement('a');
bookmark_element.setAttribute('href', url);
bookmark_element.setAttribute('title', title);
bookmark_element.setAttribute('rel', 'sidebar');
bookmark_element.click();
}
}
</script>
Now I want my bookmark to run a piece of JavaScript code instead of surfing to Google, when the user clicks on it.
I've written a code that has successfully created a bookmark for any of the following browsers - IE, Firefox and Opera.
<script language="JavaScript" type="text/javascript">
function bookmark()
{
var title = 'Google';
var url = 'http://google.';
if (document.all)// Check if the browser is Internet Explorer
window.external.AddFavorite(url, title);
else if (window.sidebar) //If the given browser is Mozilla Firefox
window.sidebar.addPanel(title, url, "");
else if (window.opera && window.print) //If the given browser is Opera
{
var bookmark_element = document.createElement('a');
bookmark_element.setAttribute('href', url);
bookmark_element.setAttribute('title', title);
bookmark_element.setAttribute('rel', 'sidebar');
bookmark_element.click();
}
}
</script>
Now I want my bookmark to run a piece of JavaScript code instead of surfing to Google, when the user clicks on it.
Share Improve this question edited Jun 3, 2010 at 13:15 David M 72.9k13 gold badges163 silver badges187 bronze badges asked Jun 3, 2010 at 13:12 Arjun VasudevanArjun Vasudevan 8724 gold badges15 silver badges34 bronze badges2 Answers
Reset to default 7This is called a bookmarklet. You could try replacing 'http://google.' with "javascript:alert('Annoying message');
". However, Firefox at least doesn't allow adding bookmarklets using this API. I suspect IE and Opera may be the same.
You can try putting the js code in an html and then bookmark that html.
本文标签: clickRunning a JavaScript code when a browser bookmark is clickedStack Overflow
版权声明:本文标题:click - Running a JavaScript code when a browser bookmark is clicked - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741232067a2362292.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论