JavaScript Firefox Bookmarklet: Exposing functions to the global namespace

I'm working on a moderately-complex Bookmarklet that works just fine in Chrome, but I can't get it to work in Firefox. When I run my Bookmarklet in Firefox it redirects to a new page that only says true on it.

I've narrowed the cause down to a very specific thing: Firefox doesn't seem to like when you expose new functions to the global namespace.

If this is the case, might you know more about it? Is this documented anywhere, such that I can learn more about it? Resources on the nuances of bookmarklet-building seem scarce, and I can't find anything relevant. A second question would be if there are there any known workarounds.

And for some examples (remember, to test them simply copy these lines of code into a bookmarklet in Firefox. Then run them on any page).

Redirecting bookmarklets

javascript:!function(){window.okay={test:function(){}}}();

The project I'm working on

A Non-redirecting bookmarklet

javascript:!function(){window.okay={test:!0}}();

Any thoughts? Thanks!

For now, I plan to use manual subscriptions in Knockout to get the functionality I need. It'd still be nice to know the answer to this question, though.

Answer:1

I've a website with the google maps api which is loaded asynchronous. But this throws a errer: google is not found. My code is: <script> function initialize() { var mapOptions = { zoom: ...

I've a website with the google maps api which is loaded asynchronous. But this throws a errer: google is not found. My code is: <script> function initialize() { var mapOptions = { zoom: ...

  1. google maps marker icons
  2. google maps marker color
  3. google maps marker label
  4. google maps marker size
  5. google maps marker api
  6. google maps marker cluster
  7. google maps marker icon size
  8. google maps marker title
  9. google maps marker options
  10. google maps marker label position
  11. google maps marker tooltip
  12. google maps marker svg
  13. google maps marker click event
  14. google maps marker infowindow
  15. google maps marker images
  16. google maps marker events
  17. google maps marker style
  18. google maps marker hover
  19. google maps marker text
  20. google maps marker url

I have the following demo data. var demoData= [{"EntryGroupDate":"November 2013", "DisplayName": "Hans Meier (November)", "EntryGroupDateSort": 11}, {"...

I have the following demo data. var demoData= [{"EntryGroupDate":"November 2013", "DisplayName": "Hans Meier (November)", "EntryGroupDateSort": 11}, {"...

I am trying to make a web form which has the option to add and remove a new element. I can get this working as buttons outside of the source or cloned elements, but I am having a problem getting a '...

I am trying to make a web form which has the option to add and remove a new element. I can get this working as buttons outside of the source or cloned elements, but I am having a problem getting a '...

  1. jquery remove cloned element
  2. jquery remove cloned row
  3. jquery remove cloned object
  4. jquery remove clone
  5. jquery remove clone div
  6. jquery remove clone append
  7. jquery remove clone table
  8. jquery remove clone on click
  9. jquery clone remove class
  10. jquery clone remove id
  11. jquery clone remove attribute
  12. jquery clone remove events
  13. jquery clone remove values
  14. jquery clone remove original
  15. jquery clone remove data

I've been experimenting and it seems like only form elements and the window object can trigger the keypress event. I checked MDN documentation, and also the spec, but couldn't find anywhere that ...

I've been experimenting and it seems like only form elements and the window object can trigger the keypress event. I checked MDN documentation, and also the spec, but couldn't find anywhere that ...