bookmarklet将参数添加到url并重新提交?

时间:2015-02-12 13:04:02

标签: javascript bookmarklet

使用书签可以实现以下目的吗?

  1. 向网址添加其他参数(include_docs = true)
  2. 重新提交网址
  3. 我有这个,但它在firefox上无声地失败。我还没有尝试过其他浏览器:

    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('&'); 
      }()
    );
    

1 个答案:

答案 0 :(得分:5)

无需过度复杂化任何事情; - )

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

这应该可以解决问题。以书签形式:

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