Sign in to follow this  
Followers 0
supergg02

Js Library In Ie.au3

12 posts in this topic

If you like to use javascript code in your IE.au3 library, just put you code in a string " " and call eval method:

exemple:

$my_JS_code="document.cookie;"

$cookies=$oIE.eval($my_JS_code)

Msgbox(1,"Cookies given by JS",$cookies)

It act as bookmarklet !!

this method is very helpful if you are easy with JS than IE COM

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#include <IE.au3>
$v =_IEAttach("AutoIt Forums")
$v.eval("alert('hello');")

Error:

The requested action with this object has failed

edit:

this works though

#include <IE.au3>
$v = _IECreate()
$v.document.write("<script language='javascript'>alert('hello');</script>")

but that replaces all the text (i know, document.write does that)

What's goin on?

edit again:

found a solution

#include <IE.au3>
$v = _IECreate()
$v.navigate("http://www.autoitscript.com")
_IELoadWait($v)
$v.document.parentwindow.execscript("alert('yo')")

~cdkid

Edited by cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

it is better to use eval than execscript, because execscript return nothing/or boolean result ! but with eval give you all type of result (object, strings...)

but i don't know if eval is a function for $oIE object or $IE.document...

Edited by supergg02

Share this post


Link to post
Share on other sites

Ah, well, this is how eval is used

$oIE.document.parentwindow.eval("alert('test')")

:)

~cdkid


AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Ah, well, this is how eval is used

$oIE.document.parentwindow.eval("alert('test')")

:mellow:

~cdkid

Right !

But, theorikly, eval work with all DOM object (Window, document, elements....)

Any way, with eval we can do anything more than getting reference for all IE object com.

so you need only IE.create or attach ! The rest ( get elements, forms,....) can be called with JScript throw eval methode :)

Great !

No need for waiting new IE.au3 update (excuse me Dale :)

Edited by supergg02

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hmm, I think Eval and ExecScript have two totally different purposes, because

Dim $ie
$ie = ObjCreate("InternetExplorer.Application")
$ie.visible = True
$ie.navigate("file:///c:\program%20files\test.htm")
$ie.document.parentwindow.execscript("document.forms[0].elements['whoa'].value = 'testthis';")

(that's just an html with an inputbox labeled 'whoa' as the ID)

that works

but

Dim $ie
$ie = ObjCreate("InternetExplorer.Application")
$ie.visible = True
$ie.navigate("file:///c:\program%20files\test.htm")
$ie.document.parentwindow.eval("document.forms[0].elements['whoa'].value = 'testthis';")

Doesn't.

I've also found a way to execute VBScript code

$ie.document.Parentwindow.ExecScript('MsgBox "hello"',"vbscript")

~cdkid

Edited by cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

$ie.document.parentwindow.eval("document.forms[0].elements['whoa'].value = 'testthis';")

work for me ! it work exactly as bookmarklets !

the problem with ExecScriptis is that did not return a result (only null ou boolean, i thing)

but may be you can use ExecScript to give a result in a temp global variable/object like this:

ExecScript(" var MyTempVar=yous JS_code_here_returning_a_wanted_result ;")

and after that you get it $ie.document.MyTempVar

dont know if there is better idea

Edited by supergg02

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

No you can do this to get the value of variables

$ie = ObjCreate("InternetExplorer.Application")
$ie.visible = true
$ie.navigate("file:///c:\program files\test.htm")
$parwin = $ie.document.parentwindow
$parwin.execscript("var q = 10;")
$q = $parwin.eval("q")
msgbox(0,'',$q)

That'll msgbox 10

PS:

Eval is working for changing text etc... i dont know why it wasnt working before, must've misspelled somewhere

Edited by cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!

Share this post


Link to post
Share on other sites

No you can do this to get the value of variables

$ie = ObjCreate("InternetExplorer.Application")
$ie.visible = true
$ie.navigate("file:///c:\program files\test.htm")
$parwin = $ie.document.parentwindow
$parwin.execscript("var q = 10;")
$q = $parwin.eval("q")
msgbox(0,'',$q)

That'll msgbox 10

PS:

Eval is working for changing text etc... i dont know why it wasnt working before, must've misspelled somewhere

Ok, so we can say that eval and execscript are a good alternative for IE.au3 library (sure, for those feeling easy with javascript than IE COM object) and you can have access for all user variable/object defined in the html page !! with IE COM, I dont thing so...

I don't know why Dale dont use it enougth in his great UDF ?

Share this post


Link to post
Share on other sites

Ok, so we can say that eval and execscript are a good alternative for IE.au3 library (sure, for those feeling easy with javascript than IE COM object) and you can have access for all user variable/object defined in the html page !! with IE COM, I dont thing so...

I don't know why Dale dont use it enougth in his great UDF ?

I'm sure there are many things Dale plans to add over time... I remember when he first made it... and to see it now WOW! He's a stickler for detail though... doesn't lay claim to anything unless it's been put through the ringer and back again!

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I'm sure there are many things Dale plans to add over time... I remember when he first made it... and to see it now WOW! He's a stickler for detail though... doesn't lay claim to anything unless it's been put through the ringer and back again!

wait and see :)

I have just a question: I wish to test the speed of the post/get forms via InetGet, _ INetGetSource, Curl, wget. Did you have any idea who can i handle that ?

(I thing that _ INetGetSource don't give possibility for sending header and cookies but if it can use proxy i can use it with proxomitron, so don't worry about cookies and headers: I just want to mesure speed of each solution)

I will ask the same question in support forum but if you have an idea ? thinks

Share this post


Link to post
Share on other sites

wait and see :)

I have just a question: I wish to test the speed of the post/get forms via InetGet, _ INetGetSource, Curl, wget. Did you have any idea who can i handle that ?

(I thing that _ INetGetSource don't give possibility for sending header and cookies but if it can use proxy i can use it with proxomitron, so don't worry about cookies and headers: I just want to mesure speed of each solution)

I will ask the same question in support forum but if you have an idea ? thinks

No not really... you guys are in a league of your own when it comes to that stuff :mellow:...

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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