提交按钮并输入 url

Submit button with enter an url

我正在尝试创建一个小书签,它捕获用户所在的当前页面的 url,将此 url 放入页面上表单的文本字段中,然后然后通过 虚拟 按提交按钮提交表单。

用下面的代码我得到了当前页面的url,转到urlhttp://example.com/?url=http://www.url-of-the-current-page的站点,将urlhttp://www.url-of-the-current-page填入表单的文本字段,但表单本身仍未提交:

javascript:(function(){ window.open('http://example.com/?url='+encodeURIComponent(location.href))})();

但是我怎样才能提交表单按钮呢?整个表格如下所示:

<form ng-submit="launchTest()" class="ng-pristine ng-valid"> 
<input type="text" name="url" ng-model="url"> 
<input type="submit" value="Launch test" class="launchBtn" ng-class="{disabled: !url}"> 
</form> 

我尝试了两种变体 - 但都失败了:在这两种变体中我都停留在 http://example.com?url=http://www.url-of-the-current-page:

javascript:(function(){ window.open('http://example.com/?url='+encodeURIComponent(location.href));document.forms[0].submit()})();

javascript:(function(){ window.open('http://example.com/?url='+encodeURIComponent(location.href));document.forms[this.form.id].submit()})();

(代表OP发表).

我已经联系了网站的所有者,我想要 运行 我的小书签 - 他说,我的小书签是正确的,但是为了提交表格,url 应该包含一个特殊的参数,例如 &run=1。使用此参数,此线程中提到的每个小书签都有效(有效意味着不仅打开新选项卡并输入 url,而且还提交表单)。我将使用的工作小书签是:

javascript:(function(){var win=window.open('http://example.com?url='+encodeURIComponent(window.location.href )+'&run=1','_blank');win.focus();})()