/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Giving control back to the browser

Hi,

When I am trying to inject below javascript in to IE browser.

[CODE]Step1: window.location = “http://www.google.com”
Step2: document.getElementsByName(“q”)[0].value=”Script Value”[/CODE]

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!!

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@KorApr 01.2011 — 
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.[/QUOTE]

That is simply impossible. JavaScript is a client-side language, thus all the change it might provoke on the document are lost when the session changes. Even if you might reach the Step 2 (in some browsers it looks like you can), it will be of no use.

What, in fact, is your real need? Maybe cookies might resolve it, but definitely not in this manner.
Copy linkTweet thisAlerts:
@krieyaauthorApr 01.2011 — Actually, I have kept the whole javascript code in a .htm page and I have configured the .htm to get execute upon selecting a item from IE context menu.

Script is getting executed very fine however when i select the context menu item, control is transferred to the javascript and once the whole execution is done then only control is giving back to the browser.

However I want it in such a way, javascript file should get execute only when the browser is in ready state and it should wait when the browser is in busy (i.e., loading) state.

Any suggestions to get this task done?
Copy linkTweet thisAlerts:
@KorApr 01.2011 — I have asked you what you want to do, not [I]what do you think[/I] about how that has to be done. Can you detail, in simple words? An hypothetical example, for instance.
Copy linkTweet thisAlerts:
@krieyaauthorApr 01.2011 — Sorry for that KOR, I thought it would be clear if i mention you how my script should go.

Here is a simple example.

I want to run a script to,

1. Navigate to www.google.com

2. Set search text

3. click search button.

here is the script.

[CODE]<script language="javascript">
window.location="www.google.com";
document.getElementsByName("q")[0].value="Search Text";
document.getElementsByName("btnG")[0].click();
</script>[/CODE]


Please suggest me how to inject the above script in to IE browser.

I agree with your previous reply. If we run the above script from a webpage, it won't work, as soon as the page navigates to other URL, javascript will also be refreshed hence I am trying to inject the script into the browser.
×

Success!

Help @krieya spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...