Page 1 of 1

How to give control back to the browser from javascript

Posted: Fri Apr 01, 2011 7:03 am
by krieya
Hi,

When I am trying to inject below javascript in to IE browser.
Step1: window.location = "http://www.google.com"
Step2: document.getElementsByName("q")[0].value="Script Value"
Javascript engine executing the first step and then before the page getting navigated to "http://www.google.com", it is trying to execute the next step.

Since the page is not completly loded, script could not able to find the text field that it has to set and throwing an error: "Internet Explorer Script Error"

I have tried "setTimeout" function, however the problem is: Browser taking the control back after the whole script is getting executed and then page is getting navigated to the page "http://www.google.com"

Here I want to execute the Step1 and then give control back to the browser from my javascript file so that browser loads the page completely and then I want to take back the control then execute the Step2.

Please guide me!!

Thanks!!

Re: How to give control back to the browser from javascript

Posted: Fri Apr 01, 2011 1:13 pm
by McInfo
The scope is limited to the page the JavaScript is embedded in. If you redirect by changing the window location, the earlier page's JavaScript will have no control of the later page.

If you are interested in manually running JavaScript on other domains, use the Developer Tools in IE8+. For a single-user, automated solution, research Greasemonkey.

Re: How to give control back to the browser from javascript

Posted: Sat Apr 02, 2011 3:21 am
by krieya
I have tried grease monkey, it works w.r.t domain names and in my application all pages are of the same domain.

So I am trying to inject my javascripts directly into IE using IE extensions.

Any suggestions how to develop IE extensions to inject javscripts into IE browser.