Sign in to follow this  
Followers 0
tphant0m

Inject Javascript Into IE When onbeforeunload Event Exists

4 posts in this topic

I'm trying to inject a bit of javascript into a page to change a few variables.

However the page has an onbeforeunload event.,

window.onbeforeunload = afunction;

<body onbeforeunload="afunction">

thus when i try put java script: lines into the address bar, this event fires (because it thinks im trying to navigate away from the page).

i have tried a _IEDocReadHTML then remove the events, then a _IEDocWriteHTML (and a _IEAction($oIE, "refresh")) so it actually loads up.

however when executing the refresh the onbeforeunload even still loads. (the page im trying to play with deflares a frameset (i understand i HAVE to do that refresh so it actually builds the frame set again).

i think im looking for some way to execute javascript in that browser instance via COM or something similar, anything that wont fireaway a navigate away style event.

any ideas would be great :P

Share this post


Link to post
Share on other sites



A "why?" woudl be a good inclusion.

In addition, the URL to the site in question would be helpful.

(of course, failure to provide both of the above lead to suspicion of bad motive.)


Reading the help file before you post... Not only will it make you look smarter, it will make you smarter.

Share this post


Link to post
Share on other sites

You could try overriding the current event with something like this:

$oIE.document.body.onbeforeunload=';'

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

A "why?" woudl be a good inclusion.

In addition, the URL to the site in question would be helpful.

(of course, failure to provide both of the above lead to suspicion of bad motive.)

lol classic,

the why? is as follows.

Daily i work with a system that has an awful awful timeout function, that expires your login after x minutes.

Now this being more security by obstruction as opposed to REAL security, is nothing more than a hassle.

The result is unless you take note of this particular system every 30mins you have to keep logging in.

The timer is a setInterval() so the idea is just a simple case of using a clearInterval() however ironicly thru mere fluke

the code also seems to have a onbeforeupload (to remove cookies when you logout).

Trying to inject javascript via the addressbar causes IE to trigger a NavitageAway and then the onbeforeupload kicks in clearing the cookies, logging the user out the system and is the opposite of what i am trying to achieve with the timer.

following? :P

If i can't seem to get very far in the next few days ill reconstruct the page and throw on the web (its on an intranet). But if Dales suggestion works, everything should be fine *cross fingers*

You could try overriding the current event with something like this:

CODE: AutoIt

$oIE.document.body.onbeforeunload=';'

Thanks Dale, ill give that a go tomorrow when i get to work

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0