PM's Blog

Pramod Mohanan's notes about ASP.NET, MVC, C#, SQL, jQuery, Bootstrap

Setting up a popup as bookmark in browser, script injection

Recently had a case in hand to auto-fill a large multi-page form in a SPA for quick tests. This was a repetitive task so it made sense to have a script for it. The script had to be injected locally on my browser which then filled-in the form based on the type of fill that I selected. I achieved this by adding a bookmark to open a popup which then displayed different buttons for various type of auto-fill I needed.

Setting up the browser to open your popup.

In the address(URL) of the bookmark I used the following javascript to open my ‘fill-options’ html page as a pop."","test_autofiller","width=400,height=450,location=0,menubar=0,status=1,toolbar=0,resizable=1,scrollbars=1");

The html had all the scripting that was required to update the form of the parent (i.e. window.opener) and popuplated the form as required. This way of injecting will work smoothly only if the html/scripts are hosted on the same domain or you may run into cross-domain issues. To avoid this we can go a step further to inject the whole popup using javascript.

Going a step further – avoiding HTML and doing it all in javascript

This can be achieved by using the following as URL for the bookmark

javascript:void("","my_autofiller","width=400,height=441,location=0,menubar=0,status=1,toolbar=0,resizable=1,scrollbars=1").document.write("<script language='JavaScript' src=''></"+"script>"));

bookmark.js then uses document.write to populate html, auto-fill scripts on the popup window.

Note: I have used https instead of http as mordern browsers block/disable popup or its contents if the source is not over served over https

Leave a Reply

Your email address will not be published. Required fields are marked *

PM's Blog © 2018