English 中文(简体)
如何在此按钮上附加 Javascript 代码?
原标题:How to attach javascript code to this button?

我用这个代码创建了一个简单的按钮:

  <toolbarpalette id="BrowserToolbarPalette">

      <toolbarbutton id="ok-nav"
                     class="toolbarbutton-1 chromeclass-toolbar-additional"
                     label="&okok;"
                     tooltiptext="&okok;" />
  </toolbarpalette>

我要把这个书签附加到那个按钮上:

javascript:(function(){window.open( http://example.com/test/mm.php?title= +encodeURIComponent(document.title))})();

有人能告诉我 我怎样才能把这个书签 附加到那个按钮上?

问题回答

首先, 您需要在覆盖中添加一个 < code\\ lt; script> 元素。 然后, 在脚本中, 以下代码片断会帮助您在按钮激活时执行动作 。

window.addEventListener("load", function () {
  document.getElementByid("ok-nav").addEventListener("command", function () {
    // do your bookmarklet here
  });
});    

我认为或许值得阅读XUL testor ,尤其是关于重叠的部分:

我敢打赌你会经常用这个 查查JQuery...

使用 JQuery 您可以很容易地使用这个 :

$(document).on( click ,  #BrowserToolbarPalette , function(){

window.open( http://example.com/test/mm.php?title= +encodeURIComponent(document.title));

});




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jQuery block moving

I wanna move a div block to the top, so I coded like this: CSS part: .movingPart{ margin-top:80px; } jQuery part: $(document).ready(function() { $( #btn ).click(function() { $( .movingPart )....

Private FireFox plugin

I m looking at getting a FireFox plugin developed - but is it possible to create a plugin that is for private use only, so only those I share it with have it and not open to the masses? Need this for ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Cross-browser development

I m developing a web application for a new service, starting from Firefox 3.5. The interface design is tableless, only using divs + CSS & performance-blessed practices. Now, while being ...

Cross browser way of setting IFrame to "about:blank"?

Does anybody know a proper, cross-browser way to "empty" an IFrame? Is "about:blank" recognized without error across all browsers? Is it valid to give an IFrame an empty src?

热门标签