I'm currently working on a bookmarklet that can grab the URL of the page the user is on, insert that URL into a text field on a specific form, and then automatically submit the form.
Here is the code I have so far. It successfully captures the current page's URL, redirects to a specific site with the URL parameter included, and fills the form's text field with the URL. However, the form itself does not automatically submit:
javascript:(function(){ window.open('http://example.com/?url='+encodeURIComponent(location.href))})();
My question is: How can I make the form submit automatically? The HTML code for the form is as follows:
<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>
I have tried two different approaches, but unfortunately, I have been unsuccessful. In both cases, I remain on the same page
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()})();