Sign in to follow this  
Followers 0
scriptkitty

Html Fun

11 posts in this topic

Soon we may have a really nice GUI built in to Autoit, but some times there may be time that you wish to just do some HTML stuff, or testing.

Simple HTML can be done quite easy with AutoIt3, this example displays what ever you have in the clipboard.:

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Platform:       Win9x / NT
AutoItSetOption("TrayIconDebug", 1)
AutoItSetOption("WinTitleMatchMode", 2)

$file="temp.htm"
$color="#FFFFFF"
$title="My AutoIt3 Html"
If FileWriteLine($file, "<title>"&$title&"</title>")=0 Then exit
FileWriteLine($file, "<body bgcolor="& $color &"><font size=-2>" )
If StringInStr(" "&clipget(),"<br>")>0 Then
    FileWriteLine($file, clipget() )
Else
    FileWriteLine($file, StringReplace(clipget(),@CRLF,"<br>") )
EndIf
FileWriteLine($file, "<br><center><a href=close()>close</a>" )
Run('C:\Program Files\Internet Explorer\IEXPLORE.EXE -k '& @ScriptDir &'\'&$file,'',@SW_HIDE)
WinWait ( $title, "") 
WinMove ( $title, "", 10, 10, 400, 400) 
WinShow ($title, "", @SW_RESTORE) 
While winexists($title)
sleep(10)   
Wend
winclose($title)
winclose("Cannot find server")
FileDelete($file)

sorry, only explorer version.


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites



Thats pretty nice i tested it out also good to learn from great job.


[font="Courier"]Dont do things bass ackwards?[/font]

Share this post


Link to post
Share on other sites

now i need a good way to get info FROM the html... like put a couple of checkboxes, and when you close it, somehow have autoit aware of what was selected or typed in or whatever..

Share this post


Link to post
Share on other sites

You could run('start '& @ScriptDir &'\'&$file), as the default browser should be assosiated with html.

Also, to read back, you could simply set the title. This program waits for it to finish anyway. All you need is a little javascript.

<script>mytitle="someTitle";</SCRIPT>
<FORM>
Have you had a nice day?
<INPUT TYPE="checkbox" NAME="niceday" VALUE="yes" onclick="document.title=mytitle+' result='+this.form.niceday.checked">
</FORM>

This is an example only, I haven't tested it.

Hope that helps


00110100010001110110111101100100

Share this post


Link to post
Share on other sites

Ey man, is good.

I think that, can be used for something like a quick display summary... :angry:

I would suggest for compatibility, use @ProgramFilesDir B)

:whistle:

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

32767, nice HTML addition. It works fine, but it is a bit tricky to place in due to both quotes and double quotes being used.

I changed double quote " to # and did string replace to get it in. With this type of code, you can get info from the HTML form, and have AutoIt act acordingly.

I also removed the returns, but would be easy to add back.

; code sniblit.
$java=StringReplace("<script>mytitle=#someTitle#;</SCRIPT><FORM>Have you had a nice day?<INPUT TYPE=#checkbox# NAME=#niceday# VALUE=#yes# onclick=#document.title=mytitle+' result='+this.form.niceday.checked#></FORM>","#",'"')
FileWriteLine($file,$java)

PS, M Internet Explorer has the Kiosk Mode, I can't seem to get it to work with Mozilla/Netscape. So I am limited to IE for the moment.

I think you could get the default browser with this code:

$x=RegRead("HKEY_CLASSES_ROOT\http\shell\open\command","")
$Browser=StringLeft($x,StringInstr($x,".exe")+3)

Quick Code to show 32767's java in action:

AutoItSetOption("TrayIconDebug", 1)
AutoItSetOption("WinTitleMatchMode", 2)

$file="temp.htm"
$color="#FFFFFF"
$title="My AutoIt3 Html"
If FileWriteLine($file, "<title>"&$title&"</title>")=0 Then exit
FileWriteLine($file, "<body bgcolor="& $color &"><font size=2>" )
$java=StringReplace("<script>mytitle=#someTitle#;</SCRIPT><FORM>Have you had a nice day?<INPUT TYPE=#checkbox# NAME=#niceday# VALUE=#yes# onclick=#document.title=mytitle+' result='+this.form.niceday.checked#></FORM>","#",'"')
FileWriteLine($file,$java)
FileWriteLine($file, "<br><center><a href=close()>close</a>" )
Run('C:\Program Files\Internet Explorer\IEXPLORE.EXE -k '& @ScriptDir &'\'&$file,'',@SW_HIDE)
WinWait ( $title, "")
WinMove ( $title, "", 10, 10, 400, 400)
WinShow ($title, "", @SW_RESTORE)
While winexists($title) or winexists("someTitle")
if winexists("someTitle result=true") then
tooltip("Congradulations on your day!",0,0)
$color="Have a nice Day"
else
tooltip("")
endif
sleep(10)
Wend
winclose($title)
winclose("someTitle")
winclose("Cannot find server")
FileDelete($file)

if $color="Have a nice Day" then msgbox(1,"Msg",$color)
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

I'm far from being an expert in html, but would it be possible for the html page to write an ini file depending what was checked and inputed? I use iniwrite and iniread to save and read the previously inputted settings the next time the script runs. If only the html page could write an ini file, then autoit could read it. Would be much nicer to have all the input boxes on one page instead of 1 per inputbox.

Share this post


Link to post
Share on other sites

CGI, ASP, and PhP pages can write files, interact with SQL and such, but I am not all that good at Javascript. Security is one big reason.

We may have a few Javascript Gurus that would know.


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

I get some interesting results when I use your example script with XML data in the clipboard. Rather than displaying the raw xml, the field # and field content is displayed. This could have some interesting applications. :whistle:

Share this post


Link to post
Share on other sites

I'm far from being an expert in html, but would it be possible for the html page to write an ini file depending what was checked and inputed?  I use iniwrite and iniread to save and read the previously inputted settings the next time the script runs.  If only the html page could write an ini file, then autoit could read it.  Would be much nicer to have all the input boxes on one page instead of 1 per inputbox.

Sorry for the delay, I don't read often enough.

No, html can't do it without going thourgh unaceptable hoops, but hta can (assuming you have IE)

Save the following as an *.hta file, then run it. It will create c:\test.ini.

<WARNING VALUE="high">Never trust an hta. Read the source yourself and try to understand it. People can do nasty things in hta. The purpose of hta is to turn hypertext into an application, so it should be treated as one</WARNING>

I don't have any nasty code here, but ALWAYS check for yourself.

BTW, this was a quick mockup, and is not exactly elegant. If I was to actualy use this, I would clean it up a bit first. This is only meant as an example.

<HTML>
<script>
<!--
fso = new ActiveXObject("Scripting.FileSystemObject");

function ini(source){
    frm=document.main;
    autoitis=frm.autoitis[frm.autoitis.selectedIndex].value
    if(frm.fname.value==""){
        alert("First name is manditory.");
    }else if(autoitis==""){
        alert("Selection is manditory.");
    }else{
        //The next line destroys test.ini, and creates its own
        file=fso.CreateTextFile("c:\\test.ini",1);
        file.WriteLine("[test]");
        file.WriteLine("fname="+frm.fname.value);
        file.WriteLine("autoitis="+autoitis);
        file.WriteLine("happy="+(frm.happy.checked?frm.happy.value:""));
        file.close();
        window.close();
    }
}
// -->
</SCRIPT>
<BODY>
<FORM onsubmit="return false" NAME="main">
Your first name <INPUT TYPE="text" NAME="fname" SIZE="10"><BR>
<SELECT NAME="autoitis">
    <OPTION VALUE="">Please select
    <OPTION VALUE="good">Autoit is good
    <OPTION VALUE="powerfull">Autoit is powerfull
    <OPTION VALUE="a time saver">Autoit is a time saver
</SELECT><BR>
Are you happy <INPUT TYPE="checkbox" VALUE="yes" NAME="happy" CHECKED><BR>
<INPUT TYPE="button" VALUE="Send Request" onclick="ini()">
</FORM>
</BODY>
</HTML>

00110100010001110110111101100100

Share this post


Link to post
Share on other sites

Nice work :whistle:

This will help out something else I was doing. B)

just a quick change to make it into a sloppy AutoIt code:

AutoItSetOption("WinTitleMatchMode", 2);2 = Match any substring in the title

dim $x[36]
$x[1]='<HTML><script>'
$x[2]='<!--'
$x[3]='fso = new ActiveXObject("Scripting.FileSystemObject");'
$x[4]='function ini(source){'
$x[5]='   frm=document.main;'
$x[6]='   autoitis=frm.autoitis[frm.autoitis.selectedIndex].value'
$x[7]='   if(frm.fname.value==""){'
$x[8]='       alert("First name is manditory.");'
$x[9]='   }else if(autoitis==""){'
$x[10]='       alert("Selection is manditory.");'
$x[11]='   }else{'
$x[12]='       //The next line destroys test.ini, and creates its own'
$x[13]='       file=fso.CreateTextFile("test.ini",1);'
$x[14]='       file.WriteLine("[test]");'
$x[15]='       file.WriteLine("fname="+frm.fname.value);'
$x[16]='       file.WriteLine("autoitis="+autoitis);'
$x[17]='       file.WriteLine("happy="+(frm.happy.checked?frm.happy.value:""));'
$x[18]='       file.close();'
$x[19]='       window.close();'
$x[20]='   }'
$x[21]='}'
$x[22]='// -->'
$x[23]='</SCRIPT><BODY>'
$x[24]='<FORM onsubmit="return false" NAME="main">'
$x[25]='Your first name <INPUT TYPE="text" NAME="fname" SIZE="10"><BR>'
$x[26]='<SELECT NAME="autoitis">'
$x[27]='   <OPTION VALUE="">Please select'
$x[28]='   <OPTION VALUE="good">Autoit is good'
$x[29]='   <OPTION VALUE="powerfull">Autoit is powerfull'
$x[30]='   <OPTION VALUE="a time saver">Autoit is a time saver'
$x[31]='</SELECT><BR>'
$x[32]='Are you happy <INPUT TYPE="checkbox" VALUE="yes" NAME="happy" CHECKED><BR>'
$x[33]='<INPUT TYPE="button" VALUE="Send Request" onclick="ini()">'
$x[34]='</FORM>'
$x[35]='</BODY></HTML>'

$file="myhta.hta"
filedelete($file)
for $i= 1 to 35
filewriteline($file,$x[$i])
next
Run('start '& $file,'',@SW_HIDE)
WinWait("myhta")
While winexists("myhta")
sleep(100)
Wend
$inifile="test.ini"
$x=FileRead($iniFile,FileGetSize($iniFile))
MsgBox(1,"ini file reads",$x)

AutoIt3, the MACGYVER Pocket Knife for computers.

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