Reputation: 21
I found one post with title as "Issue with Form Auto-Submit with JS code written in browser's address bar" and the solution provided worked for me.
Now my requirement is, I want to run my following javascript commands once the third party web application's login page has been loaded.
javascript:document.getElementById('Username').value='xyz';document.getElementById('Password').value='xyz_123';document.getElementById('Destination').value='TestDB';document.getElementById('cmdLogin1').click();
Please note that the application I am trying to login to is a third party application and I DO NOT HAVE ACCESS TO THE SOURCE CODE.
Currently what I am doing is, I have created a bookmark with URL as above mentioned code, when the login page is loaded, I am clicking on the bookmark and thus the login fields gets filled and page gets submitted automatically.
I just want to bypass this manual intervention and want some way to automatically run the above JS commands as soon as the login page loading is completed.
Please help.
Thanks Shridhar
Upvotes: 2
Views: 2248
Reputation: 438
Or you can create a very simple extension:
You will need two files:
yourCode.js // Here goes your code
manifest.json // Here you target the page
Here is what you should put in manifest.json
:
{
"manifest_version": 2, // Mandatory
"name": "Auto-submit form", // Mandatory
"version": "1.0", // Mandatory
"content_scripts": [ // This key injects your js file into any target website.
{
"matches": ["your target url"], // Pattern: "*://*/*"
"js": ["yourCode.js"]
}
]
}
And your code resides in yourCode.js
:
document.getElementById('Username').value='xyz';
document.getElementById('Password').value='xyz_123';
document.getElementById('Destination').value='TestDB';
document.getElementById('cmdLogin1').click();
Now you have your extension and can install it on your desired browser.
In Firefox go to about:debugging > This Firefox > Load Temporary Add-on
In Chrome go to chrome://extensions > Developer Mode > Load unpacked extension.
Upvotes: 0
Reputation: 73251
You can use a userscript for this, e.g.:
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match http://<websiteUrlHere>
// @grant none
// ==/UserScript==
/* jshint -W097 */
'use strict';
document.getElementById('Username').value='xyz';
document.getElementById('Password').value='xyz_123';
document.getElementById('Destination').value='TestDB';
document.getElementById('cmdLogin1').click();
Just replace the @match
with the url you need this to run on, and load the userscript via tampermonkey or greasemonkey, depending on the browser you are using - tampermonkey for chrome or greasemonkey for firefox.
Upvotes: 3