Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Appending a VBScript output to Iframe src

Status
Not open for further replies.

Payo10

MIS
Oct 11, 2011
9
0
0
What im trying to do is to grab the computer usermane (doing it with a VBscript in an HTA file) and appending the usermane to an Iframe src at the end. Im not sure how to pass the output from my VBscript to be used on the Iframe. here is my code

<head>
<title>HTA Tutorial</title>
</head>

<script language="VBScript">

Sub callSub

Dim objNetwork

Set objNetwork = CreateObject("WScript.Network")

strUserName = objNetwork.UserName

MsgBox strUserName


End Sub

</script>

<body>

<span id=DataArea></span>

<iframe style="width:100%; height:100%" src='
</body>

</html>
 
[red]1. assign an id to the iframe[/red]
[blue]2. alter the vbs sub to accept an argument[/blue]
[green]3. access the element by id passed to the sub and modify the .src[/green]
[purple]4. call the sub after all HTML has be written, otherwise the element won't be accessible.[/purple]

Code:
<head>
	<title>HTA Tutorial</title>
</head>

<script language="VBScript">
	sub [blue]addUserName(strElement)[/blue]
		dim objNetwork
		Set objNetwork = CreateObject("WScript.Network")
		strUserName = objNetwork.UserName
		
		[green]set objElement = document.getElementById(strElement)
		objElement.src = objElement.src & strUserName[/green]
		
	end sub
</script>

<body>
	<span id = "DataArea"></span>
	<iframe [red]id = "frame1"[/red] style="width:100%; height:100%" src="[URL unfurl="true"]https://somepage.com/dir/username="></iframe>[/URL]
</body>

[purple]
<script language="VBScript">
	addUserName("frame1")
</script>
[/purple]

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
That was a fast respond, thank you very much, i knew it had to do with passing parameters to functions but not a programmer here. thanks again Geates, it works!
 
Bare in mind that this one of several ways to do it. This particular approach will only work in IE. VBS is not supported in other browsers. But because it is an .hta (IE-only format), I don't think you'll run into other issues.

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
I have been requested some additional modifications to this code. The code is beeing used to check if a particular user is registered on a security system, if it hasn't completed the registration process the user is presented with a form, if the user has completed registration then a different webpage is presented saying thank you (all this within the same frame). Now what they want is to automatically close the window if the user has registered. Is there a way to check what page is being display(I was thinking somehow grabbing the current page SRC and compared it to the THANK YOU page SRC, and use the idTimer = window.setTimeout, to clse the HTA) and then decide to close the window or leave it running??
 
Sounds right. Grab the iframe src and look for a certain phrase. If found implement the timeout.

Code:
set objElement = document.getElementById("myElement")

strSource = objElement.src

if (inStr(strSource, "Thank You")) then
   wait 5 seconds
   close hta
else
   do registration
end if

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
I made the modifications to my code, but the code its grabbing the original page SRC and not the SRC after the redirection. In order for it to work properly I need to grab the SRC after the rederection occurs to that THANK YOU Page (if user has registered), maybe I need to call that fuction at a different time??

<head>

<title>HTA Tutorial</title>

</head>

<script language="VBScript">

sub addUserName(strElement)
dim objNetwork
Set objNetwork = CreateObject("WScript.Network")
strUserName = objNetwork.UserName

set objElement = document.getElementById(strElement)
objElement.src = objElement.src & strUserName

end sub

sub getSrc

set objcElement = document.getElementByI("frame1")

strSource = objcElement.src

Document.Write strSource

End Sub




</script>


<body>

<span id = "DataArea"></span>
<iframe id = "frame1" style="width:100%; height:100%" src="
</body>




<script language="VBScript">

addUserName("frame1")

getSrc

</script>
 
Call it after the user has been redirected. Actually, if this were the case, there is no need for the function at all. Might as well put the relavent code in the redirected pages.

-Geates

NOTE: please put your code in [ignore]
Code:
[/ignore] tags to preserve formatting.

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
This is the code I added at the end and its working the way I wanted it to work. Thank you for all your input Geates.

<script language = "VBScript">
Sub Window_OnLoad
idTimer = window.setTimeout("PausedSection", 5000, "VBScript")
End Sub

Sub PausedSection

if window.frames(0).location.href = " Then
window.close
End If

End Sub
</script>
 
Hello there!,, In addition to what I've done to this script, the new task is to force users to registered to the secury system. If they decide to close the window and not registered, then the script should log the user off the computer. So, my plan is to check if the window for registration is open or running, and display a message every 5 minutes asking the user to registered, if they close the registration window then log the user off. The problem that i'm encountering is how to check if the registration window is open or exists. Any help in the correct path would be appreciated. thank you in advance
 
does the registration window have a title? If so, use objShell.AppActivate to bring focus to the window and close it.

Code:
set objShell = CreateObject("Wscript.Shell")
strTitle = "Registration"

boolWindowOpen = objShell.AppActivate(strTitle)
if (boolWindowOpen) then msgbox "Window open"

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top