AvWG wrote:
> With vbscript I.ve created the following:
> I start the IE-application, use sendkeys to login in on a site. Next I
> create 10 more tabs (internet-pages), each with slightly another address.
> When this is done I want to go to the 2nd tab, save the source information
> and do this for the rest of the 9 remaining tabs....
>
hi AvWG,
Unless you are using microsoft's tab control (with its own
methods and properties), then you will have to "roll-yer-own"
tab control. There are several examples of how to do this
via html/dhtml posted on the web. Lets say you decide to
implement your own tab control using a series of (html) buttons.
In that case, you can select the tab you want using a
button.click statement.
I have attached a script which shows a row of "made-up" tabs,
which is just a row of buttons. The trick here is in how you
"decorate" the buttons. I found the underlying tab control code
on the web, but can't remember where I found it (sorry if the
real author is lurking out there). Anyway, if you decide to do
something like this, you can see what it would take to "click-
a-tab".
Beyond that, if you just want to open a series of webpages
one-at-a-time, then I agree with mayayana -- you don't need
any tabs to do that...
cheers, jw
__________________________________________________ __________
You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)
p.s. Achtung Vorsicht! If you decide to try out the attached
script (er, I mean hta) then you will discover that it is not
fully debugged, and was only taken to the "proof-of-concept"
point. If you dismiss the error dialogs, you should get a
working "tab control". Also, don't get too annoyed with the
comments promising to show a "fake status bar" -- that isn't
there. I used another script as a template but didn't clean
up the comments. Sorry about that.
Note also, the extensions of the "hta" file and the accompanying
"css" file were changed to "txt", to avoid having any nasty AV
software from screening them out as "malicious" scripts.
<HTML>
<HEAD>
<script language="vbscript">
' --- discussion (avoiding that annoying hta "dialog bounce") ---
' this "trick" found on the vbScript ng, code by mikHar, 05Sept06
' Normally, an hta dialog will initially be shown in its "default"
' position and size for a brief instant. Later, when it gets
' around to running your script code, it will move/resize itself
' according to your wishes. Placing the move/resize code AHEAD
' of the hta tag seems to avoid that...
' --- end of discussion ----------------------
Const wdDlg = 600, htDlg = 380 ' dialog size
Const pxLeft = 100, pxTop = 100 ' positioning
window.ResizeTo wdDlg,htDlg
window.MoveTo pxLeft,pxTop
</script>
<HTA:APPLICATION ID="oHTA" APPLICATIONNAME="htaDebugDialogTemplate"
WINDOWSTATE="normal" SCROLL = "no" BORDERSTYLE="normal" BORDER="thin"
CAPTION="yes" MAXIMIZEBUTTON="no" MINIMIZEBUTTON="no" ICON="mru.ico"
SHOWINTASKBAR="yes" SINGLEINSTANCE="yes" SYSMENU="yes" VERSION="1.0" >
<TITLE> << (hta) Debug Dialog Template (with Fake StatusBar) Demo Script >> </TITLE>
<!-- bring in stylesheet for the "tab control buttons" -->
<link rel="stylesheet" type="text/css" href="tabStyles.css">
<SCRIPT LANGUAGE="vbScript">
<!--
' --- description block --------------------------
'
' Title: (hta) debug dialog with Fake StatusBar, jw 12May06
'
' Description: A scripting graphical user interface (gui),
' appropriate for posting debugging messages or status msgs.
' Due to difficulties with posting messages to microsoft's
' IE statusbar, there is also a "fake" statusbar included...
'
' Author: mr_unreliable
' Website: none at this time (but lurks around the wsh/vbs ng's)
'
' Usage: Use at you own risk, tested on win98se...
'
' --- revision history ---------------------------
' 12May06: initial attempt (working from "regular" hta dbDlg)...
' 13May06: added "working clock"...
' 20May06: added "scroll into view" option for scrolling...
' 05Dec07: NOTA BENE: this script needs "tabStyles.css" in the same sub-directory...
' --- end of description block -------------------
Option Explicit
' --- global variables ---------------------------
'
' Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
' Dim oShell : Set oShell = CreateObject("WScript.Shell")
'
Dim oDoc ' as document object
Dim clkTmr ' as timer (used to update clock)
Const clkTmrInt = 995 ' clock update interval (note: LESS THAN 1 SEC)
'
Dim tRun ' as long (to keep track of running time)
Dim iItem ' as integer (to keep track of "span" tags)
Dim iMsg ' as integer (sequential number, to keep track of messages)
Const bAlignWithTop = True
Const bAlignWithBottom = False
' --- end of declarations and constants ----------
' --- INITIALIZATION ROUTINE ---------------------
Sub initDialog()
Const sMe = "[initDialog], "
' do a little adjusting of my size and location...
' window.ResizeTo wdDlg,htDlg
' window.MoveTo 100,100
Set oDoc = window.document
Call tabLoad()
With oDoc
' resize text area...
oDoc.getElementById("msgList").style.width = wdDlg - 25
' htClientArea, less statusbar, logo, less button, less progbar, less...
oDoc.getElementById("msgList").style.height = oDoc.body.clientHeight _
- 25 - 20 - 35 - 20 ' (and less fudge factor, but don't tell anybody)...
' MsgBox("Client Width: " & oDoc.body.clientWidth _
' & "Client Height: " & oDoc.body.clientHeight)
' re-position the logo to lie just above the (fake) statusbar...
oDoc.getElementById("logo").style.top = oDoc.body.clientHeight - 47
oDoc.getElementById("logo").style.left = oDoc.body.clientWidth - 215
' re-position the (fake) statusbar at the bottom of the form (er, dialog)...
oDoc.getElementById("etchedEdge").style.top = oDoc.body.clientHeight - 25
oDoc.getElementById("fakeStatusBarFrame").style.to p = oDoc.body.clientHeight - 23
' oDoc.getElementById("btnExit").disabled = False
oDoc.getElementById("btnExit").onClick = GetRef("btnExit_Click")
End With
' place a message in the main statusbar panel...
oDoc.getElementByID("statusPanel1").innerText = " The ""Main"" statusbar panel text goes here "
' place the current time in the clock panel of the statusbar...
oDoc.getElementByID("statusPanel2").innerText = " Time: " _
& formatDateTime(Time, vbLongTime)
' set clock timer, (used to update the clock)...
ClearInterval(clkTmr) : clkTmr = setInterval("clkTimer_Event", clkTmrInt, "vbscript")
tRun = 0 ' initialize the running time...
iItem = 0
dbPrint sMe & "finished.. "
' hiding the dbMsgs, for now...
oDoc.getElementByID("msgLabel").style.visibility = "hidden"
oDoc.getElementByID("msgList").style.visibility = "hidden"
msgBox("pause2")
End Sub
' --- SIMULATE DEBUG.PRINT -----------------------
Sub dbPrint(sMsg) ' simulates debug.print...
Dim msgID ' as string
' posting messages and scrolling down (take II)...
' In this version, the posted messages are "wrapped" into "span tags",
' and given an "id" attribute containing the "message number",
' then inserted into the listing...
msgID = "msg" & CStr(iMsg)
oDoc.getElementById("msgList").insertAdjacentHTML "BeforeEnd", _
"<span id=""" & msgID & """ >" & sMsg & "<br></span>"
' and the current/last span tag (message) is scrolled into view...
oDoc.getElementByID(msgID).scrollIntoView(bAlignWi thBottom)
' also, publish the current dbMessage in the (fake) statusbar panel...
oDoc.getElementByID("statusPanel1").innerText = " " & sMsg
iMsg = iMsg + 1 ' bump up for next message
End Sub
Sub old2_dbPrint(sMsg) ' simulates debug.print...
Dim colSPANs ' as collection
Dim msgID ' as string
With oDoc ' saves a little typing...
' posting messages and scrolling down (take II)...
' In this version, the posted messages are "wrapped" into "span tags"
msgID = "msg" & CStr(iMsg)
.getElementById("msgList").insertAdjacentHTML "BeforeEnd", _
"<span id=""" & msgID & """ >" & sMsg & "<br></span>" ' add message to listing
' find all the span tags, and gather into a collection...
' Set colSPANs = .getElementsByTagName("span")
' and the last span tag (message) is scrolled into view...
' colSPANs(colSPANs.Length - 1).scrollIntoView(bAlignWithBottom)
.getElementByID(msgID).scrollIntoView(bAlignWithBo ttom)
iMsg = iMsg + 1 ' bump up for next message
End With ' oList
End Sub
Sub old1_dbPrint(sMsg) ' simulates debug.print...
Dim colSPANs ' as collection
Dim cMsgs ' as integer (msg count)
With oDoc ' saves a little typing...
' .insertAdjacentText "BeforeEnd", sMsg & vbCrLf ' add message to listing
' ok, so paging down is unsophisticated and overkill,
' but the lesser (scrolling) increments don't seem to work for me.
' If you know the "right way" to do this, then kindly let me know...
' (and yes, I do realize that you don't need any scrolling for the
' first seven or so entries, you can add that code for yourself)...
' .doScroll("pageDown")
' posting messages and scrolling down (take II)...
' In this version, the posted messages are "wrapped" into "span tags",
' and the span tag is "scroll(ed)IntoView"...
.getElementById("msgList").insertAdjacentHTML "BeforeEnd", "<span>" & sMsg & "<br></span>" ' add message to listing
' .all.Tags("span")(iItem).scrollIntoView(bAlignWith Bottom)
' .getElementsByTagName("span")(iItem).scrollIntoVie w(bAlignWithBottom)
' Set colSPANs = .getElementsByTagName("span")
' cMsgs = colSPANs.Length
' colSPANs(cMsgs - 1).scrollIntoView(bAlignWithBottom)
' cMsgs = colSPANs.Length
' scroll "last message" into view...
Set colSPANs = .getElementsByTagName("span")
colSPANs(colSPANs.Length - 1).scrollIntoView(bAlignWithBottom)
iItem = iItem + 1 ' bump up for next item
End With ' oList
End Sub
' ------------------------------------------------
' --- EVENT HANDLERS -----------------------------
' ------------------------------------------------
Sub clkTimer_Event() ' update the clock
Const sMe = "[timer], "
' msgbox("timer event detected")
oDoc.getElementByID("statusPanel2").innerText = " Time: " _
& formatDateTime(Time, vbLongTime)
' every to often, post a debug message, just for the entertainment value...
tRun = tRun + 1
' if ((tRun mod 10) = 0) then dbPrint sMe & "elapsed time: " & CStr(tRun) & " secs"
dbPrint sMe & "elapsed time: " & CStr(tRun) & " secs"
End Sub
Sub btnExit_Click()
Const sMe = "[btnClick], "
' MsgBox("detected Click Event")
ClearInterval(clkTmr) ' stop the clock timer
' post a notification to the debug window...
dbPrint "" ' space
dbPrint sMe & " ..detected Exit Button Click Event "
dbPrint sMe & " (this window will close in 1 sec) "
' wait-a-bit, to allow for reading the msg,
' by setting ANOTHER timer, to close this dialog window...
SetTimeout "Window.Close", 1000
End Sub
Sub CleanUp()
' msgbox("onUnload event detected")
ClearInterval(clkTmr)
End Sub
//-->
</SCRIPT>
<SCRIPT LANGUAGE="vbScript" TITLE="Setup Tab Controls" >
<!--
' --- execute NOW (gloal variables) --------------
Const tabAlign = "Left"
Dim saURLs : saURLs = Array("MSDN|http://msdn.microsoft.com", _
"CNN|http://www.cnn.com", _
"NASA|http://www.nasa.gov", _
"Google|http://www.google.com|*", _
"Forbes|http://www.forbes.com")
Dim cTabs : cTabs = UBound(saURLs)
' --- end of global variables --------------------
Sub tabLoad()
Dim sHTML : sHTML = "<P ALIGN=" & tabAlign & "> "
Dim i ' as integer
Dim saTAB ' as string array
' add onMouseOver, onMouseOut...
For i = 0 to cTabs ' create button control(s)
saTAB = Split(saURLs(i),"|")
' msgBox(saTAB(0) & saTAB(1))
sHTML = sHTML & "<BUTTON ID=tab" & CStr(i) _
& " CLASS='tabOff' VALUE=" & saTAB(1) _
& " onClick='tabOnClick(" & CStr(i) & ")'>" _
& saTab(0) & "</BUTTON>"
' if (i = 0) then msgbox(sHTML)
Next ' i
divTabButtons.innerHTML = sHTML ' insert tab buttons into first div
Call tabOnClick(3) ' set the 4th tab as default...
MsgBox("pause")
End Sub ' tabLoad
Sub tabOnClick(iTab)
Dim oElement ' as object
Dim i ' as integer
For i = 0 to cTabs ' set ALL tabs to "taboff" style...
' msgbox(i)
Set oElement = document.getElementById("tab" & CStr(i))
oElement.className = "tabOff"
Next ' i
' then, highlight the selected tab...
Set oElement = document.getElementById("tab" & CStr(iTab))
oElement.className = "tabOn"
' and setup the appropriate contents of the "tab" (i.e., iframe it)...
' var tab = tabs[ID].split("|");
divTabFrame.innerHTML = "<IFRAME SRC='about
:blank' CLASS='tabFrame'></IFRAME>"
' to avoid drawing the "focus rectangle" around the tab button...
document.body.focus()
End Sub ' tabOnClick
//-->
</SCRIPT>
<style>
body {font-family: ms sans serif; font-size: 10pt; font-weight: 400; color: Navy;
margin-top: 4px; margin-left: 1px; margin-right: 1px; margin-bottom: 1px;
height: 10px; width: 10px; border-style: none; }
div.listBox {border-style: inset; border-width: 2; background-color:aliceblue;
overflow:auto; text-align:left;
font-family:verdana; font-size:10pt; font-weight:400; color:Navy; }
textarea {font-family: verdana; font-size: 10pt; font-weight: 400; color: Navy; }
button {margin-top: 7px; height: 25px; width: 100px; font-family: verdana; font-weight: 600;
width: 125px; }
h3 {margin-top: 3px; margin-bottom: 2px; padding-top: 0%; padding-bottom: 0%;
font-family: verdana; font-size: 8pt; font-weight: 400; color: Navy; }
h4 {position:absolute; top:100; left: 2;
margin-top: 6px; margin-bottom: 0px; padding-top: 0%; padding-bottom: 0%;
font-family: Arial; font-size: 8pt; font-weight: Normal; font-style: Italic;
color: Navy; }
hr {position:absolute; top:100; left: 2; margin-top: 1px; margin-bottom: 1px; }
table {position:absolute; top:110; left: 1; margin-top: 1px; margin-bottom: 1px;
border-style: none; border-width: 1; width: 100%; height: 20px; }
td {border-style: inset; border-width: 2;
font-family: verdana; font-size: 8pt; font-weight: normal; color: Navy }
</style>
</HEAD>
<!-- this is the "mother" (a.k.a. "debug dialog") page -->
<BODY onload="initDialog()" onUnload="CleanUp()" scroll='no' text='navy' bgcolor="silver" >
<DIV ID="divTabButtons"></DIV>
<CENTER>
<DIV ID="divTabFrame">
<h3 id="msgLabel" > debugging messages... </h3>
<CENTER>
<!-- using "div" element (instead of textarea) for posting messages,
instead of a listbox (i.e., what you would have used in
vb)... -->
<DIV id="msgList" class="listBox">
</CENTER>
</DIV>
<BUTTON id="btnExit" onclick="window.close()" >Exit</BUTTON>
</CENTER>
<h4 id="logo" ALIGN=RIGHT > jawar productions (all rights reserved)... </h4>
<!-- using table as (fake) statusbar. (with "inset" border) -->
<hr id="etchedEdge" width=99% align=center >
<TABLE id="fakeStatusBarFrame" width=99% bgcolor=silver align=center ><TR>
<TD id="statusPanel1" bgcolor=silver >
<TD id="statusPanel2" style="width: 120px; "> Time 12:00:00 </TR></TABLE>
</BODY>
</HTML><style type="text/css">
<!--
.tabOff { WIDTH: 90; HEIGHT: 20;
FONT-FAMILY: Verdana;
FONT-SIZE: 10;
FONT-WEIGHT: 700;
TEXT-ALIGN: CENTER;
COLOR: Navy;
BACKGROUND-COLOR: LightSteelBlue;
BORDER-BOTTOM: LightSteelBlue 1PX SOLID;
CURSOR: HAND;
}
.tabOn { WIDTH: 90; HEIGHT: 23;
FONT-FAMILY: Verdana;
FONT-SIZE: 10;
FONT-WEIGHT: 700;
TEXT-ALIGN: CENTER;
COLOR: White;
BACKGROUND-COLOR: LightSlateGray;
BORDER-BOTTOM: LightSlateGray 1PX SOLID;
BORDER-TOP: DarkOrange 2px SOLID;
CURSOR: HAND;
}
.tabFrame {
ORDER: 0;
HEIGHT: 50%;
WIDTH: 99%;
COLOR: Black;
BORDER-TOP: LightSlateGray 3px SOLID;
BORDER-BOTTOM: LightSlateGray 3px SOLID;
BORDER-LEFT: LightSlateGray 3px SOLID;
BORDER-RIGHT: LightSlateGray 3px SOLID;
SCROLLBAR-FACE-COLOR:#6699CC;
SCROLLBAR-HIGHLIGHT-COLOR:#FFFFFF;
SCROLLBAR-SHADOW-COLOR:#6699CC;
SCROLLBAR-ARROW-COLOR:#FFFFFF;
SCROLLBAR-DARKSHADOW-COLOR:#6699CC;
}
// -->
</style>