#85990 - 2002-06-09 10:07 PM
Write to IE using interhtml??
|
Anonymous
Anonymous
Unregistered
|
I would like to display a "CountDown Timer" In an HTML page (W2K/IE6/Kix4.02). I am trying to do this withe the following code patched together from this site. (I thank all whom contributed).. I can not get the time to update. What have I done wrong?
code:
$password2 = "test" $maxtime = 15 $timeout = 0
$Ipass = HTMLInputBox("Enter Override Password:","System Shutdown","","Enter","Shutdown Now") ? "Ipass= " $Ipass exit
;HTML Input Box: ; SYNTAX: ; HTMLInputBox("HTML Message", OPTIONAL "Window Title", OPTIONAL "Default Value",OPTIONAL "Button Text", OPTIONAL "Alt Button Text", OPTIONAL "Alt Button Return Value") ; ; PARAMETERS: ; HTML Message: The message for the Input Box. ex: What is your favorite color? Note: This can accept any HTML code, so go to town! Also Note: the <b> tag is enabled, so if you want to do custom HTML, put </b> as the first tag. ; Window Title: ( OPTIONAL ) The title of the HTML Input Box Window. If blank, defaults to "Question...". ; Default Value: ( OPTIONAL ) The default value for the box which will show when the box appears. If blank, defaults to blank. ; Button Text: ( OPTIONAL ) The text on the main button. If blank, default is "SUBMIT". ; Alt Button Text: ( OPTIONAL ) If this is specified, an alternate button will appear on the form and if clicked, the function will (by default) return "-1". This is useful as a "HELP" button, or for many other purposes. ; Alt Button Return Value: ( OPTIONAL ) If the Alt button is needed, and -1 is a potential legitimate return value for the main submit button, you can specify an alternate return value for the alternate button. ; RETURNS: ; The string in the text box, or another value if the "Alternate button" is pressed. The alternate value defaults to -1, but can be changed by specifying the "Alt Button Return Value". ; ; EXAMPLE: HTMLInputBox("Enter Override Password:","System Shutdown","","Enter","Shutdown Now")
FUNCTION HTMLInputBox($L_Prompt, OPTIONAL $L_Title, OPTIONAL $L_DefaultValue, OPTIONAL $L_ButtonText, OPTIONAL $L_AltButtonText, OPTIONAL $L_AltButtonReturnValue)
IF $L_Title = "" $L_Title = "Question..." ENDIF
IF $L_ButtonText = "" $L_ButtonText = "Submit" ENDIF
IF $L_AltButtonReturnValue = "" $L_AltButtonReturnValue = -1 ENDIF $L_TextColor = "FFFF00" $L_BGColor = "000000"
$HTML = '<HTML>' + '<BODY scroll=no TEXT=' + $L_TextColor + ' BGCOLOR=' + $L_BGColor + '>' + '<TITLE>' + $L_Title + '</TITLE><B>' + $L_Prompt + '</B>' + '<form name=MyForm>' + '<BR>' + '<input id=Answer name=Answer type=password class=tbox' + ' value="' + $L_DefaultValue + '" Tabindex="1"> ' + '<input id=Submitted name=Submitted type=hidden value=0>' + '<input id=Submit name=Submit type=button value=" ' + $L_ButtonText + ' "' + ' onclick="MyForm.Submitted.value=1" Tabindex="2">' + '<input id=Time name=Time ' + ' value="' + $Maxtime + '" >'
IF $L_AltButtonText <> "" $HTML = $HTML + '<input id=AltButton name=AltButton type=button value=" ' + $L_AltButtonText + ' "' + ' onclick="MyForm.Submitted.value=2" Tabindex="3">' ENDIF $Bottomtext = "This system has been started in an improper state and will conduct a Shutdown in $maxtime seconds. " + "Shutdown is required to Re-Image this system. To override shutdown, Enter the correct password... " $HTML = $HTML + '<BR>$Bottomtext</BR></FORM>' + '</BODY></HTML>'
$appIE = CREATEOBJECT("InternetExplorer.Application")
;Set IE Object Properties $appIE.top = 180 $appIE.left = 380 $appIE.height = 240 $appIE.width = 500 $appIE.addressbar = 0 $appIE.menubar = 0 $appIE.toolbar = 0 $appIE.statusbar = 0 $appIE.resizeable = 0 $appIE.navigate("about:blank") WHILE $appIE.busy <> 0 AND @ERROR = 0 LOOP
;Write the HTML code to the document $appIE.document.write($HTML)
WHILE $appIE.busy <> 0 AND @ERROR = 0 LOOP
;Make IE visible and set focus $appIE.visible = 1 $= SETFOCUS("about:blank - Microsoft Internet Explorer") $appIE.document.GetElementById("Answer").focus
DIM $L_LastBoxValue,$L_LastBoxValueCache WHILE $appIE.document.GetElementById("Submitted").value = 0 and $timeout < $maxtime IF $appIE.document.GetElementById("Submit").value = " " + $L_ButtonText + " " IF $appIE.document.GetElementById("Answer").value <> "" $L_LastBoxValue = $appIE.document.GetElementById("Answer").value IF $L_LastBoxValue <> "" $L_LastBoxValueCache = $L_LastBoxValue ENDIF ENDIF ENDIF sleep(1) $timeout=$timeout+1 $appIE.document.Time.interhtml = $maxtime-$timeout LOOP
IF $appIE.document.GetElementById("Submitted").value = 2 $HTMLInputBox = $L_AltButtonReturnValue ELSE $HTMLInputBox = $L_LastBoxValueCache ENDIF
$appIE.QUIT $appIE = "" ENDFUNCTION
[ 09 June 2002, 23:33: Message edited by: Dana Eddy ]
|
|
Top
|
|
|
|
#85993 - 2002-06-09 11:10 PM
Re: Write to IE using interhtml??
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
This is cool...
I'd make it a bit more 'generic' in function, but this rocks.
It has much more functionality than the XLSInput box that I have been using.
Great job!!
|
|
Top
|
|
|
|
#85994 - 2002-06-10 12:28 AM
Re: Write to IE using interhtml??
|
Anonymous
Anonymous
Unregistered
|
Thanks Shawn It worked!! Try this one. Sorry about the Long Lines.....
code:
$password2 = "test" $maxtime = 15 $timeout = 0
$Ipass = HTMLInputBox("Enter Override Password:","System Shutdown","","Enter","Shutdown Now") ? "Ipass= " $Ipass exit
;HTML Input Box: ; SYNTAX: ; HTMLInputBox("HTML Message", OPTIONAL "Window Title", OPTIONAL "Default Value",OPTIONAL "Button Text", OPTIONAL "Alt Button Text", OPTIONAL "Alt Button Return Value") ; ; PARAMETERS: ; HTML Message: The message for the Input Box. ex: What is your favorite color? Note: This can accept any HTML code, so go to town! Also Note: the <b> tag is enabled, so if you want to do custom HTML, put </b> as the first tag. ; Window Title: ( OPTIONAL ) The title of the HTML Input Box Window. If blank, defaults to "Question...". ; Default Value: ( OPTIONAL ) The default value for the box which will show when the box appears. If blank, defaults to blank. ; Button Text: ( OPTIONAL ) The text on the main button. If blank, default is "SUBMIT". ; Alt Button Text: ( OPTIONAL ) If this is specified, an alternate button will appear on the form and if clicked, the function will (by default) return "-1". This is useful as a "HELP" button, or for many other purposes. ; Alt Button Return Value: ( OPTIONAL ) If the Alt button is needed, and -1 is a potential legitimate return value for the main submit button, you can specify an alternate return value for the alternate button. ; RETURNS: ; The string in the text box, or another value if the "Alternate button" is pressed. The alternate value defaults to -1, but can be changed by specifying the "Alt Button Return Value". ; ; EXAMPLE: HTMLInputBox("Enter Override Password:","System Shutdown","","Enter","Shutdown Now")
FUNCTION HTMLInputBox($L_Prompt, OPTIONAL $L_Title, OPTIONAL $L_DefaultValue, OPTIONAL $L_ButtonText, OPTIONAL $L_AltButtonText, OPTIONAL $L_AltButtonReturnValue)
IF $L_Title = "" $L_Title = "Question..." ENDIF
IF $L_ButtonText = "" $L_ButtonText = "Submit" ENDIF
IF $L_AltButtonReturnValue = "" $L_AltButtonReturnValue = -1 ENDIF $L_TextColor = "FFFF00" $L_BGColor = "000000"
$HTML = '<HTML>' + '<BODY scroll=no TEXT=' + $L_TextColor + ' BGCOLOR=' + $L_BGColor + '>' + '<TITLE>' + $L_Title + '</TITLE><B>' + $L_Prompt + '</B>' + '<form name=MyForm>' + '<BR>' + '<input id=Answer name=Answer type=password class=tbox' + ' value="' + $L_DefaultValue + '" Tabindex="1"> ' + '<input id=Submitted name=Submitted type=hidden value=0>' + '<input id=Submit name=Submit type=button value=" ' + $L_ButtonText + ' "' + ' onclick="MyForm.Submitted.value=1" Tabindex="2">'
IF $L_AltButtonText <> "" $HTML = $HTML + '<input id=AltButton name=AltButton type=button value=" ' + $L_AltButtonText + ' "' + ' onclick="MyForm.Submitted.value=2" Tabindex="3">' ENDIF $Bottomtext = "This system has been started in an improper state and will conduct a Shutdown in $maxtime seconds. " + "Shutdown is required to Re-Image this system. To override shutdown, Enter the correct password... " $HTML = $HTML + '<BR><Center>$Bottomtext</BR><H1><input id=Time name=Time value="' + + '" ></H1></FORM>' + '</Center></BODY></HTML>'
$appIE = CREATEOBJECT("InternetExplorer.Application")
;Set IE Object Properties $appIE.top = 180 $appIE.left = 380 $appIE.height = 300 $appIE.width = 500 $appIE.addressbar = 0 $appIE.menubar = 0 $appIE.toolbar = 0 $appIE.statusbar = 0 $appIE.resizeable = 0 $appIE.navigate("about:blank") WHILE $appIE.busy <> 0 AND @ERROR = 0 LOOP
;Write the HTML code to the document $appIE.document.write($HTML)
WHILE $appIE.busy <> 0 AND @ERROR = 0 LOOP
;Make IE visible and set focus $appIE.visible = 1 $= SETFOCUS("about:blank - Microsoft Internet Explorer") $appIE.document.GetElementById("Answer").focus
DIM $L_LastBoxValue,$L_LastBoxValueCache WHILE $appIE.document.GetElementById("Submitted").value = 0 and $timeout < $maxtime IF $appIE.document.GetElementById("Submit").value = " " + $L_ButtonText + " " IF $appIE.document.GetElementById("Answer").value <> "" $L_LastBoxValue = $appIE.document.GetElementById("Answer").value IF $L_LastBoxValue <> "" $L_LastBoxValueCache = $L_LastBoxValue ENDIF ENDIF ENDIF sleep(1) $timeout=$timeout+1 $appIE.document.GetElementById("time").value = $maxtime-$timeout LOOP
IF $appIE.document.GetElementById("Submitted").value = 2 $HTMLInputBox = $L_AltButtonReturnValue ELSE $HTMLInputBox = $L_LastBoxValueCache ENDIF
$appIE.QUIT $appIE = "" ENDFUNCTION
|
|
Top
|
|
|
|
#85998 - 2002-06-10 10:13 PM
Re: Write to IE using interhtml??
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
Could you look at this and see where it is failing... It just blows right through it. The buttons and such appear, but it doesn't wait for the user to type/click
code:
Function IEInputBox($window, Optional $prompt, optional $Ok, optional $Cancel) Dim $click, $html
If not $prompt $prompt = "Please enter your password." endif If not $ok $ok = "OK" endif If not $Cancel $cancel = "Cancel" endif
$html = ' <html><head><style> <!---body{ background-color: silver; color: black;font-family: tahoma, arial; font-size: 10pt; margin: 3px "input.tbox { border: lpx black solid;}td { font: 10pt tahoma; }---> </style></head> <body scroll=no > <table align=center> <form name=frm> <tr> <td align=right>$prompt </td> <td colspan=2><input id=password1 type=password value="" class=tbox></td> </tr> <tr> <td><input id=ok type=button value=" $ok " onclick="frm.status.value=1"> <input type=hidden id=status name=status value=0></td> <td align=right><input id=cancel type=button value=" $Cancel " onclick="frm.status.value=2"></td> </tr> </form> </table></body></html>'
$window.document.write('$html') WHILE $window.busy <> 0 AND @ERROR = 0 LOOP
$=setfocus($window.title+" - Microsoft Internet Explorer") $window.GetElementById("password1").focus $status = $window.GetElementById("status") $click = $window.GetElementById("password1") while @error = 0 and $status.value = "" select case $status.value = "1" ;Ok was clicked $IEInputBox = $password1.value case $status.value = "2" ;cancel was clicked $IEInputBox = "Cancel" endselect loop $window.quit $window="" EndFunction
|
|
Top
|
|
|
|
#86000 - 2002-06-11 08:04 AM
Re: Write to IE using interhtml??
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11631
Loc: CA
|
Hey Rad... you're not shooting blanks are you?
Shawn,
I take that back, you're going to make 3,000 before July unless you slow down.
Shawn, could you explain in further detail what is wrong with the method Radimus is using?
|
|
Top
|
|
|
|
#86001 - 2002-06-12 12:45 AM
Re: Write to IE using interhtml??
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
that almost defeats the point of the library of subs... if each sub has to duplicate the function of another.
|
|
Top
|
|
|
|
#86003 - 2002-06-11 02:42 PM
Re: Write to IE using interhtml??
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
here is my current IE lib. needless to say most of it doesn't work, the windows get created and get populated, but the event handling, the focus, and such do not work. Most of these functions do not work at all (work in progress) and the rest do not work correctly.
My concept is to create a 'gui' console using IE, and when necessary for user input\popup messages use IE comboboxes, input fields, etc. HTML can 'simulate' many of the functions and appearance of kixforms/kixgui windows, yet doesn't require an extra dll to be distributed.
code:
break on ;$=setconsole("minimize")
$Window = IECreateWindow("This Damn Thing",300,300,640,480)
IEWrite($Window,"hello","Arial","4","#00ff00") IEWrite($Window,"hello1",,"2","#ff0000") IEWrite($Window,"hello2","Courier","5","#0000ff") IEWrite($Window,"hello3")
$b1=IEAddButton($Window,"Button1",10,0,50,25) $b2=IEAddButton($Window,"Button2",70,0,50,25) $b3=IEAddButton($Window,"Button3",130,0,50,25)
? IEInputBox("What is your name?", "Enter your name")
?"pause..." get$k
$window.quit $window = 0 exit 1
;*********************************************************************************************** Function IECreateWindow($title,$left,$top,$width,$height, optional $html) $ie = createobject("internetexplorer.application") $ie.addressbar = 0 $ie.menubar = 0 $ie.toolbar = 0 $ie.statusbar = 0 $ie.top = $top $ie.left = $left $ie.width = $width $ie.height = $height $ie.navigate("about:blank") while $ie.busy and $ie.readystate <> 4 and @error = 0 loop $ie.document.body.scroll = no if $html $ie.document.write('$html') else $ie.document.write('<title>$title</title>') endif $ie.document.body.bgcolor = "threedface" $ie.document.body.border = "1px solid #cccccc" $IECreateWindow = $ie $ie.Visible = 1 while setfocus("$title") <> 0 loop EndFunction
Function IEWrite($Window,$text, optional $font, optional $size, optional $color, optional $Clear) if not $font $font='Verdana, Helvetica, sans-serif' endif if not $size $size='3' endif if not $color $color='#000000' endif if not $bgcolor $bgcolor='#ffffff' endif $HTML = '<font size="$size" FACE="$font" color="$color">$text<br></font>' $window.document.write($HTML) WHILE $window.busy <> 0 AND @ERROR = 0 LOOP EndFunction
Function IEAddButton($Window,$Caption,$Left,$Top,$Width,$Height) dim $Button $Button = $Window.Document.CreateElement("input") $Button.Type = "Button" $Button.Value = $Caption $Button.Style.Position = "Absolute" $Button.Style.PixelTop = $Top $Button.Style.PixelLeft = $Left $Button.Style.PixelWidth = $Width $Button.Style.PixelHeight = $Height $Button = $Window.Document.Body.AppendChild($Button) $IEAddButton = $Button EndFunction
Function IESetBackColor($Window,$Color) $Window.Document.Body.BGColor = $Color EndFunction
Function IEComboBox($Window,$title,$text,$ElementArray)
$html='<HTML><HEAD><TITLE>$title</TITLE></HEAD><BODY><BR>$text<BR> <OBJECT ID="ComboBox" WIDTH=200 HEIGHT=24 CLASSID="CLSID:8BD21D30-EC42-11CE-9E0D-00AA006002F3"> </OBJECT></BODY></HTML> ' $window.document.write('$html') WHILE $window.busy <> 0 AND @ERROR = 0 LOOP
$combobox=IE.document.GetElementById("combobox") for each $element in $ElementArray $=$combobox.additem("$Element") next $combobox.value=$ElementArray[0]
EndFunction
Function IEInputBox($title, Optional $prompt, optional $Ok, optional $Cancel) Dim $click, $html, $Window, $status, $click
If not $prompt $prompt = "Please enter your password." endif If not $ok $ok = "OK" endif If not $Cancel $cancel = "Cancel" endif
$html = ' <html><head><title>$title</title><style> <!---body{ background-color: silver; color: black;font-family: tahoma, arial; font-size: 10pt; margin: 3px "input.tbox { border: lpx black solid;}td { font: 10pt tahoma; }---> </style></head> <body scroll=no > <table align=center> <form name=frm> <tr> <td align=right>$prompt </td> <td colspan=2><input id=input value="" class=tbox></td> </tr> <tr> <td><input id=ok type=button value=" $ok " onclick="frm.status.value=1"> <input type=hidden id=status name=status value=0></td> <td align=right><input id=cancel type=button value=" $Cancel " onclick="frm.status.value=2"></td> </tr> </form> </table></body></html>'
$Window = IECreateWindow($title,100,100,300,130,$html) while $window.busy and $window.readystate <> 4 and @error = 0 loop $window.GetElementById("input").focus $status = $window.GetElementById("status") $click = $window.GetElementById("input") ? "$status $status.value @serror" while @error = 0 and $status.value <> "" select case $status.value = "1" ;Ok was clicked $IEInputBox = $password1.value case $status.value = "2" ;cancel was clicked $IEInputBox = "Cancel" endselect loop ? "$status $status.value @serror" $window.quit $window="" EndFunction
[ 11 June 2002, 19:56: Message edited by: Radimus ]
|
|
Top
|
|
|
|
#86004 - 2002-06-11 03:27 PM
Re: Write to IE using interhtml??
|
Anonymous
Anonymous
Unregistered
|
Rad & Shawn, I like where you guys are going with this. You are deffinately on to something GOOD! It will make code generation in the future a lot easier. Unfortunately, I'm under the gun to get something working out the door. For, now I'll use the code I have and watch this grow... I'll jump back in when I can (at the rate you guys are going, it will be a full fledged function lib. by then). Keep up the GREAT work & Thanks, Dana
|
|
Top
|
|
|
|
#86005 - 2002-06-11 05:31 PM
Re: Write to IE using interhtml??
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
I suppose that function IEinputbox, could call to the IEcreateWindow funct... That may seem more logically consistent than creating a window to append a combobox or whatever into it.
|
|
Top
|
|
|
|
#86006 - 2002-06-11 05:57 PM
Re: Write to IE using interhtml??
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Thats the ticket. Thats what I was trying to say in too many words before ... ![[Wink]](images/icons/wink.gif) [ 11 June 2002, 17:58: Message edited by: Shawn ]
|
|
Top
|
|
|
|
#86007 - 2002-06-11 07:54 PM
Re: Write to IE using interhtml??
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
slightly modified Updated the funct lib above...
The $status = $window.GetElementById("status") $click = $window.GetElementById("input") ? "$status $status.value @serror"
$status isn't getting data...
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
1 registered
(Allen)
and 271 anonymous users online.
|
|
|