Bookmark doesn't work on Mozilla, but does in Chrome

I wrote this bookmarklet

<a href="javascript:var m = document.getElementById('xxx'); m.value=17;">test</a>

and it works in Chrome but not in Mozilla Firefox

I even tried

<a href="javascript:var m = document.getElementById('xxx'); m.value='17';">test</a>

but it doesn't work either

what am I doing wrong?

+3
source share
2 answers

These are the steps that I recommend for creating bookmarklets:

1. Put everything in a function called immediately

You can use (function(){YOUR CODE}());or(function(){YOUR CODE})();

2. Collapse your code

You can use the online javascript script

3. URL-encode it

You can use an online encoder

In your case, it might be something like this:

(function(){m=document.getElementById('xxx');m.value=17}());

encoded as:

(function()%7Bm%3Ddocument.getElementById('xxx')%3Bm.value%3D17%7D())%3B

See DEMO .

0
source

, FF , .

<a href="javascript:void(document.getElementById('xxx').value=17)">test</a>

, .

0

All Articles