当第二次执行这段VBS程序的时候,如果先前(第一次执行)的窗口没有被关闭需要在先前的窗口中打开。
这里就需要得到打开IE窗口的句柄,不知道该如何获得,高人指点一下啊。
10 个解决方案
#1
<button onclick="vbs:openWin">open</button>
<input type="hidden" id="hhh" value="0">
<script language="vbscript">
dim win
dim a
sub openWin()
hhh.value=int(hhh.value)+1
if isobject(win) then
win.document.body.innerHTML=win.opener.document.getElementById("hhh").value +1
else
set win=window.open("about:blank")
win.document.body.innerHTML =win.opener.document.getElementById("hhh").value +1
end if
end sub
</script>
#2
稍微有一点出入。
您的程序是在一个网页里面,网页不关闭的话可以通过win对象来控制被打开的窗口。我需要的功能是类似于点击open按钮后(这里会新开个窗口),关闭您这段程序所在网页之后,再打开您这段程序所在网页,再点击open按钮,这是要求这是要求在原来开的那个窗口里面显示您的计算结果。
我的程序要求是做一个VBS程序(*.vbs文件),双击执行这个文件之后,打开一个IE窗口,在里面显示一个结果。到这里程序执行完毕,推出程序(*.vbs文件)。
当我第二次执行这个VBS程序(*.vbs文件)的时候,需要判断是否存在一个被我这个程序打开过的窗口,如果存在,那么在先前那个窗口里面显示结果,如果不存在,新开窗口打开结果。
这里面因为中间VBS程序退出了,所以可能需要类似hook一类的技术才能拿到窗口句柄,不知道有没有办法,比如通过窗口标题,进程ID之类的。
您的程序是在一个网页里面,网页不关闭的话可以通过win对象来控制被打开的窗口。我需要的功能是类似于点击open按钮后(这里会新开个窗口),关闭您这段程序所在网页之后,再打开您这段程序所在网页,再点击open按钮,这是要求这是要求在原来开的那个窗口里面显示您的计算结果。
我的程序要求是做一个VBS程序(*.vbs文件),双击执行这个文件之后,打开一个IE窗口,在里面显示一个结果。到这里程序执行完毕,推出程序(*.vbs文件)。
当我第二次执行这个VBS程序(*.vbs文件)的时候,需要判断是否存在一个被我这个程序打开过的窗口,如果存在,那么在先前那个窗口里面显示结果,如果不存在,新开窗口打开结果。
这里面因为中间VBS程序退出了,所以可能需要类似hook一类的技术才能拿到窗口句柄,不知道有没有办法,比如通过窗口标题,进程ID之类的。
#3
UP
#4
UP
#5
帮顶
#6
OPEN的时候指定窗口名称就可以了:
<script language="vbscript">
window.open "http://community.csdn.net/Expert/topic/5324/5324568.xml?temp=.9649622","csdn"
</script>
<script language="vbscript">
window.open "http://community.csdn.net/Expert/topic/5324/5324568.xml?temp=.9649622","csdn"
</script>
#7
目前只能做到这样的情况
<input type=button onclick="vbs:openWin" value=open>
<script language="vbscript">
dim win
dim a
Set win = Nothing
sub openWin()
If win Is Nothing Then
set win=window.open("about:blank")
win.document.body.innerHTML="First New"
else
If win.closed Then
set win=window.open("about:blank")
win.document.body.innerHTML="New"
Else
win.focus
win.document.body.innerHTML="Exists"
End If
end if
end sub
</script>
<input type=button onclick="vbs:openWin" value=open>
<script language="vbscript">
dim win
dim a
Set win = Nothing
sub openWin()
If win Is Nothing Then
set win=window.open("about:blank")
win.document.body.innerHTML="First New"
else
If win.closed Then
set win=window.open("about:blank")
win.document.body.innerHTML="New"
Else
win.focus
win.document.body.innerHTML="Exists"
End If
end if
end sub
</script>
#8
谢谢楼上的朋友,给了我启发,下面的代码基本可用,但是全屏的一段代码没会直接写,能不能教教我应该怎么写,现在用replace做的,哈直接用'width='+window.screen.width不好用,这块儿参数怎么做成比较好啊
Private Sub main()
Dim objNetwork
Dim portal_url
Dim user
Dim idForPassword
Dim password
Dim IE
portal_url = "url"
Set objNetwork = WScript.CreateObject("WScript.Network")
user = objNetwork.UserName
idForPassword = convertToArabia(user)
password = makePassword(idForPassword)
set IE=WScript.CreateObject("InternetExplorer.Application","event")
IE.navigate "about:blank"
with IE.document
.Write "<html>" & vbcrlf
.Write "<head>" & vbcrlf
.Write "<title>ƒiƒŒƒbƒWƒ|[ƒ^ƒ‹‚ɐڑ±’†</title>" & vbcrlf
.Write "<SCRIPT LANGUAGE='VBScript'>" & vbcrlf
.Write "Sub ReSize()" & vbcrlf
.Write " moveTo 0,0" & vbcrlf
.Write " resizeTo window.screen.width,window.screen.height" & vbcrlf
.Write "End Sub" & vbcrlf
.Write "</SCRIPT>" & vbcrlf
.Write "<SCRIPT LANGUAGE='JavaScript'>" & vbcrlf
.Write "function openSubmitWindow(){" & vbcrlf
.Write " option='toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=window.screen.width,height=window.screen.height'" & vbcrlf
.Write " option=option.replace('window.screen.width',window.screen.width)" & vbcrlf
.Write " option=option.replace('window.screen.height',window.screen.height)" & vbcrlf
.Write " window.open('about:blank','PortalLogin',option)" & vbcrlf
.Write "}" & vbcrlf
.Write "</SCRIPT>" & vbcrlf
.Write "</head>" & vbcrlf
.Write "<body onLoad='ReSize()'>" & vbcrlf
.Write "ƒiƒŒƒbƒWƒ|[ƒ^ƒ‹‚ɐڑ±‚ðŽŽ‚Ý‚Ä‚¢‚Ü‚·cc" & vbcrlf
.write "<form name=login target=PortalLogin id=login action="+portal_url+" method=POST onsubmit=openSubmitWindow() >" & vbcrlf
.write "<input type=hidden name=userid value='"+user+"'>" & vbcrlf
.write "<input type=hidden name=password value="+password+"><br>" & vbcrlf
.write "<input type=submit id=submitb name=submitb visible=false><br>" & vbcrlf
.write "</form>" & vbcrlf
.write "</body>" & vbcrlf
.write "</html>"
end with
IE.document.login.submitb.click()
IE.quit()
Set ObjNetwork = Nothing
Set IE = Nothing
End Sub
Private Sub main()
Dim objNetwork
Dim portal_url
Dim user
Dim idForPassword
Dim password
Dim IE
portal_url = "url"
Set objNetwork = WScript.CreateObject("WScript.Network")
user = objNetwork.UserName
idForPassword = convertToArabia(user)
password = makePassword(idForPassword)
set IE=WScript.CreateObject("InternetExplorer.Application","event")
IE.navigate "about:blank"
with IE.document
.Write "<html>" & vbcrlf
.Write "<head>" & vbcrlf
.Write "<title>ƒiƒŒƒbƒWƒ|[ƒ^ƒ‹‚ɐڑ±’†</title>" & vbcrlf
.Write "<SCRIPT LANGUAGE='VBScript'>" & vbcrlf
.Write "Sub ReSize()" & vbcrlf
.Write " moveTo 0,0" & vbcrlf
.Write " resizeTo window.screen.width,window.screen.height" & vbcrlf
.Write "End Sub" & vbcrlf
.Write "</SCRIPT>" & vbcrlf
.Write "<SCRIPT LANGUAGE='JavaScript'>" & vbcrlf
.Write "function openSubmitWindow(){" & vbcrlf
.Write " option='toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=window.screen.width,height=window.screen.height'" & vbcrlf
.Write " option=option.replace('window.screen.width',window.screen.width)" & vbcrlf
.Write " option=option.replace('window.screen.height',window.screen.height)" & vbcrlf
.Write " window.open('about:blank','PortalLogin',option)" & vbcrlf
.Write "}" & vbcrlf
.Write "</SCRIPT>" & vbcrlf
.Write "</head>" & vbcrlf
.Write "<body onLoad='ReSize()'>" & vbcrlf
.Write "ƒiƒŒƒbƒWƒ|[ƒ^ƒ‹‚ɐڑ±‚ðŽŽ‚Ý‚Ä‚¢‚Ü‚·cc" & vbcrlf
.write "<form name=login target=PortalLogin id=login action="+portal_url+" method=POST onsubmit=openSubmitWindow() >" & vbcrlf
.write "<input type=hidden name=userid value='"+user+"'>" & vbcrlf
.write "<input type=hidden name=password value="+password+"><br>" & vbcrlf
.write "<input type=submit id=submitb name=submitb visible=false><br>" & vbcrlf
.write "</form>" & vbcrlf
.write "</body>" & vbcrlf
.write "</html>"
end with
IE.document.login.submitb.click()
IE.quit()
Set ObjNetwork = Nothing
Set IE = Nothing
End Sub
#9
.Write " option='toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width='+window.screen.width +',height='+window.screen.height" & vbcrlf
#10
我也觉得上面那么些应该好用,可惜不好用,可能别的什么地方出问题了。哎
#1
<button onclick="vbs:openWin">open</button>
<input type="hidden" id="hhh" value="0">
<script language="vbscript">
dim win
dim a
sub openWin()
hhh.value=int(hhh.value)+1
if isobject(win) then
win.document.body.innerHTML=win.opener.document.getElementById("hhh").value +1
else
set win=window.open("about:blank")
win.document.body.innerHTML =win.opener.document.getElementById("hhh").value +1
end if
end sub
</script>
#2
稍微有一点出入。
您的程序是在一个网页里面,网页不关闭的话可以通过win对象来控制被打开的窗口。我需要的功能是类似于点击open按钮后(这里会新开个窗口),关闭您这段程序所在网页之后,再打开您这段程序所在网页,再点击open按钮,这是要求这是要求在原来开的那个窗口里面显示您的计算结果。
我的程序要求是做一个VBS程序(*.vbs文件),双击执行这个文件之后,打开一个IE窗口,在里面显示一个结果。到这里程序执行完毕,推出程序(*.vbs文件)。
当我第二次执行这个VBS程序(*.vbs文件)的时候,需要判断是否存在一个被我这个程序打开过的窗口,如果存在,那么在先前那个窗口里面显示结果,如果不存在,新开窗口打开结果。
这里面因为中间VBS程序退出了,所以可能需要类似hook一类的技术才能拿到窗口句柄,不知道有没有办法,比如通过窗口标题,进程ID之类的。
您的程序是在一个网页里面,网页不关闭的话可以通过win对象来控制被打开的窗口。我需要的功能是类似于点击open按钮后(这里会新开个窗口),关闭您这段程序所在网页之后,再打开您这段程序所在网页,再点击open按钮,这是要求这是要求在原来开的那个窗口里面显示您的计算结果。
我的程序要求是做一个VBS程序(*.vbs文件),双击执行这个文件之后,打开一个IE窗口,在里面显示一个结果。到这里程序执行完毕,推出程序(*.vbs文件)。
当我第二次执行这个VBS程序(*.vbs文件)的时候,需要判断是否存在一个被我这个程序打开过的窗口,如果存在,那么在先前那个窗口里面显示结果,如果不存在,新开窗口打开结果。
这里面因为中间VBS程序退出了,所以可能需要类似hook一类的技术才能拿到窗口句柄,不知道有没有办法,比如通过窗口标题,进程ID之类的。
#3
UP
#4
UP
#5
帮顶
#6
OPEN的时候指定窗口名称就可以了:
<script language="vbscript">
window.open "http://community.csdn.net/Expert/topic/5324/5324568.xml?temp=.9649622","csdn"
</script>
<script language="vbscript">
window.open "http://community.csdn.net/Expert/topic/5324/5324568.xml?temp=.9649622","csdn"
</script>
#7
目前只能做到这样的情况
<input type=button onclick="vbs:openWin" value=open>
<script language="vbscript">
dim win
dim a
Set win = Nothing
sub openWin()
If win Is Nothing Then
set win=window.open("about:blank")
win.document.body.innerHTML="First New"
else
If win.closed Then
set win=window.open("about:blank")
win.document.body.innerHTML="New"
Else
win.focus
win.document.body.innerHTML="Exists"
End If
end if
end sub
</script>
<input type=button onclick="vbs:openWin" value=open>
<script language="vbscript">
dim win
dim a
Set win = Nothing
sub openWin()
If win Is Nothing Then
set win=window.open("about:blank")
win.document.body.innerHTML="First New"
else
If win.closed Then
set win=window.open("about:blank")
win.document.body.innerHTML="New"
Else
win.focus
win.document.body.innerHTML="Exists"
End If
end if
end sub
</script>
#8
谢谢楼上的朋友,给了我启发,下面的代码基本可用,但是全屏的一段代码没会直接写,能不能教教我应该怎么写,现在用replace做的,哈直接用'width='+window.screen.width不好用,这块儿参数怎么做成比较好啊
Private Sub main()
Dim objNetwork
Dim portal_url
Dim user
Dim idForPassword
Dim password
Dim IE
portal_url = "url"
Set objNetwork = WScript.CreateObject("WScript.Network")
user = objNetwork.UserName
idForPassword = convertToArabia(user)
password = makePassword(idForPassword)
set IE=WScript.CreateObject("InternetExplorer.Application","event")
IE.navigate "about:blank"
with IE.document
.Write "<html>" & vbcrlf
.Write "<head>" & vbcrlf
.Write "<title>ƒiƒŒƒbƒWƒ|[ƒ^ƒ‹‚ɐڑ±’†</title>" & vbcrlf
.Write "<SCRIPT LANGUAGE='VBScript'>" & vbcrlf
.Write "Sub ReSize()" & vbcrlf
.Write " moveTo 0,0" & vbcrlf
.Write " resizeTo window.screen.width,window.screen.height" & vbcrlf
.Write "End Sub" & vbcrlf
.Write "</SCRIPT>" & vbcrlf
.Write "<SCRIPT LANGUAGE='JavaScript'>" & vbcrlf
.Write "function openSubmitWindow(){" & vbcrlf
.Write " option='toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=window.screen.width,height=window.screen.height'" & vbcrlf
.Write " option=option.replace('window.screen.width',window.screen.width)" & vbcrlf
.Write " option=option.replace('window.screen.height',window.screen.height)" & vbcrlf
.Write " window.open('about:blank','PortalLogin',option)" & vbcrlf
.Write "}" & vbcrlf
.Write "</SCRIPT>" & vbcrlf
.Write "</head>" & vbcrlf
.Write "<body onLoad='ReSize()'>" & vbcrlf
.Write "ƒiƒŒƒbƒWƒ|[ƒ^ƒ‹‚ɐڑ±‚ðŽŽ‚Ý‚Ä‚¢‚Ü‚·cc" & vbcrlf
.write "<form name=login target=PortalLogin id=login action="+portal_url+" method=POST onsubmit=openSubmitWindow() >" & vbcrlf
.write "<input type=hidden name=userid value='"+user+"'>" & vbcrlf
.write "<input type=hidden name=password value="+password+"><br>" & vbcrlf
.write "<input type=submit id=submitb name=submitb visible=false><br>" & vbcrlf
.write "</form>" & vbcrlf
.write "</body>" & vbcrlf
.write "</html>"
end with
IE.document.login.submitb.click()
IE.quit()
Set ObjNetwork = Nothing
Set IE = Nothing
End Sub
Private Sub main()
Dim objNetwork
Dim portal_url
Dim user
Dim idForPassword
Dim password
Dim IE
portal_url = "url"
Set objNetwork = WScript.CreateObject("WScript.Network")
user = objNetwork.UserName
idForPassword = convertToArabia(user)
password = makePassword(idForPassword)
set IE=WScript.CreateObject("InternetExplorer.Application","event")
IE.navigate "about:blank"
with IE.document
.Write "<html>" & vbcrlf
.Write "<head>" & vbcrlf
.Write "<title>ƒiƒŒƒbƒWƒ|[ƒ^ƒ‹‚ɐڑ±’†</title>" & vbcrlf
.Write "<SCRIPT LANGUAGE='VBScript'>" & vbcrlf
.Write "Sub ReSize()" & vbcrlf
.Write " moveTo 0,0" & vbcrlf
.Write " resizeTo window.screen.width,window.screen.height" & vbcrlf
.Write "End Sub" & vbcrlf
.Write "</SCRIPT>" & vbcrlf
.Write "<SCRIPT LANGUAGE='JavaScript'>" & vbcrlf
.Write "function openSubmitWindow(){" & vbcrlf
.Write " option='toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=window.screen.width,height=window.screen.height'" & vbcrlf
.Write " option=option.replace('window.screen.width',window.screen.width)" & vbcrlf
.Write " option=option.replace('window.screen.height',window.screen.height)" & vbcrlf
.Write " window.open('about:blank','PortalLogin',option)" & vbcrlf
.Write "}" & vbcrlf
.Write "</SCRIPT>" & vbcrlf
.Write "</head>" & vbcrlf
.Write "<body onLoad='ReSize()'>" & vbcrlf
.Write "ƒiƒŒƒbƒWƒ|[ƒ^ƒ‹‚ɐڑ±‚ðŽŽ‚Ý‚Ä‚¢‚Ü‚·cc" & vbcrlf
.write "<form name=login target=PortalLogin id=login action="+portal_url+" method=POST onsubmit=openSubmitWindow() >" & vbcrlf
.write "<input type=hidden name=userid value='"+user+"'>" & vbcrlf
.write "<input type=hidden name=password value="+password+"><br>" & vbcrlf
.write "<input type=submit id=submitb name=submitb visible=false><br>" & vbcrlf
.write "</form>" & vbcrlf
.write "</body>" & vbcrlf
.write "</html>"
end with
IE.document.login.submitb.click()
IE.quit()
Set ObjNetwork = Nothing
Set IE = Nothing
End Sub
#9
.Write " option='toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width='+window.screen.width +',height='+window.screen.height" & vbcrlf
#10
我也觉得上面那么些应该好用,可惜不好用,可能别的什么地方出问题了。哎