Chris Snow
Chris Snow

Reputation: 24588

bookmarklet to add a parameter to the url and resubmit it?

Is the following possible with a bookmarklet?

  1. Add an additional parameter to the URL (include_docs=true)
  2. Re-submit the URL

I have this but it fails silently on firefox. I haven't tried it with another browser:

javascript:(

   function()
   {
      key = encodeURI('include_docs'); value = encodeURI('true');

      var kvp = document.location.search.substr(1).split('&');

      var i=kvp.length; var x; while(i--) 
      {
        x = kvp[i].split('=');

        if (x[0]==key)
        {
            x[1] = value;
            kvp[i] = x.join('=');
            break;
        }
      }
      if(i<0) {kvp[kvp.length] = [key,value].join('=');}

      //this will reload the page, it's likely better to store this until finished
      document.location.search = kvp.join('&'); 
  }()
);

Upvotes: 3

Views: 1419

Answers (1)

Cerbrus
Cerbrus

Reputation: 72839

No need to over-complicate anything ;-)

document.location += '&include_docs=true';

That should do the trick. In bookmarklet form:

javascript:(function(){document.location+='&include_docs=true'}());

Upvotes: 6

Related Questions