Jump to content

changing javascript variable value


Recommended Posts

Hello you all! Would somebody help me with a doubt concerning javascript variables? DaleHohm posted the following:

#include <IE.au3>

$oIE = _IECreate()

_IEDocWriteHTML($oIE, "<html><head><script language = 'javascript'>foo='bar';</script></head><body></body></html>")

ConsoleWrite("foo = " & $oIE.document.parentwindow.eval('foo') & @CR)

This was in response to a user that wanted to check a javascript variable value. What if I wanted to change that value after a remote webpage has loaded? For instance, if I navigate to a site which has the code below, how can I alter the value of "x" so that I can manipulate the clock after the page is already running?

<html>
<head>
<script>
var x = 31;
var y = 1;
function startClock() {
    if (x !== 'Done') {
        x = x-y;
        document.frm.clock.value = x;
        setTimeout("startClock()", 1000);
    }
    if (x == 0) {
        x = 'Done';
        document.frm.clock.value = x;
        success.location.href="success.php";
    }
}
</script>
</head>

<body onload="startClock()">
<form name="frm">
<input name="clock" size="3" readonly="readonly" style="font-size: 25pt; font-family: Verdana;" type="text">
</form>
</body>
</html>

BTW, where can I find documentation on these stuff? I mean properties and methods like $oIE.document.parentwindow.eval ?

Thank you very much!

Link to comment
Share on other sites

Unless I miss my initial guess - it is illegal to do this.

You miss.

$oIE.document.parentwindow.eval('x=7;')

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...