For one of my projects, I was working on a minor enhancement. The project was web-based and as per client’s requirement, run only on Internet Explorer. The enhancement was related to some data input page but access to any part of the site was restricted by a Login page.
The login page, as like any, consisted of very minimal input – the username and password. But any change or recompiling on the site made me go from the login screen. Since it was pretty old (almost a decade), it never had or no one bothered to put a “Remember me” check box. So logging in through the main screen was pretty customary.
I quickly considered the other alternative of hardcoding the values into the code, or at least till the release was made. But the idea of making temporary fixes to the code for my pleasure nauseated me immediately.
What I was looking for was a very efficient way to give me a quick form fill feature on the browser without having to mutilate the project in any possible way. May be Internet Explorer had an option of extending itself! Fortunately, it did and I finally figured out a way to do exactly that.
What would be the outcome? The outcome of this simple hack procedure would provide me with a new item on the Right click menu on Internet Explorer. On clicking upon such a menu item, the fields on my form (website) would be auto filled with pre-set values.
Where all can I apply this hack? This procedure would specifically suit Internet Explorer browsers of versions anywhere in 6, 7 or 8 although this has not been tested on very recent releases of Internet Explorer. If you’re using browsers like Chrome, you have other ways of extending the browser functionality, this is just for fellow developers like me who have no other browser to turn to except Internet Explorer.
Can we get on to the hack already? Yeah sure.
All I need for this hack would be:
- A registry entry
- A simple JavaScript function
Registry entry: The whole purpose of the registry entry is to add the menu item to Internet Explorer’s context sensitive menu. As far as my knowledge goes, there isn’t a straight way of doing this than to go for a registry edit.
Warning: This section involves a registry edit. Altering registry settings without proper care might render the operating system useless. Kindly ensure necessary precautions before proceeding. Hazmat suits advised. Alternatively, you can visit this
link to back up your registry settings.
- Enter regedit in your run command prompt.
- In the registry editor, navigate to the following tree-child.
- HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\
- Create a new key under this tree element, by any name “
XYZ
” of your choice. - Under the registry item “
XYZ
”, add the following String
Values as below:
- String Value: CLSID
- Value: A guid like {1FBA04EE-3024-11D2-8F1F-0000F87ABD16}
- PS: You may use any GUID generator to get such a string
- String Value: Menu Text
- Value: My Menu Extension
- PS: This text would appear on your Internet Explorer context sensitive menu.
- String Value: Exec
- Value: Path to the HTML file, you’ll be coding in the next section.
- Example – C:\MyFolder\MyFile.html
JavaScript function:
- Place a simple JavaScript code to do the job of the form filling in an HTML file.
- Copy the location to this HTML file and place in the above registry item’s, Exec value.
- Restart your Internet Explorer.
- Navigate to your page, a right click on it – you must see “My Menu Extension” on the right click menu.
- Click on it to perform the tasks you’ve coded in the JavaScript function. Or in this case, it would fill two textboxes
txtUserId
and txtPassword
with corresponding values.
<script language="JavaScript">
var parentwin = external.menuArguments;
parentwin.document.forms.txtUserId.value ="UserName";
parentwin.document.forms.txtPassword.value ="Password";
</script>
Well, that’s how I solved my requirement with a simple concept of extending Internet Explorer. The possible areas of further work I looked into were:
- Filling huge web-forms (repetitive tasks) for let’s say testing purposes with the ease of a right-click menu item
- Automating using a Excel macro to create the registry entries and their corresponding JavaScript function for different sets of values provided. Basically abstracting the user from the nitty gritties and allowing him just the final piece of cake.
For a very detailed look into various customizations on Internet Explorer, check this link.
CodeProject
Filed under:
CodeProject,
Technology Tagged:
browser functionality