How to give control back to the browser from javascript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
krieya
Forum Newbie
Posts: 14
Joined: Sat Mar 05, 2011 12:45 am

How to give control back to the browser from javascript

Post 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!!
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

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

Post 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.
krieya
Forum Newbie
Posts: 14
Joined: Sat Mar 05, 2011 12:45 am

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

Post 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.
Post Reply