Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
771 views
in Technique[技术] by (71.8m points)

VBScript To Launch Internet Explorer With A URL Generated

Currently I'm a learning HTA programming. I have a requirement as follows.

There are two input boxes in the form (both are mandatory). When I enter the values and click on search button, a url would be created based on the inputs. The should launch the Internet Explorer application with the generated url.

My issue is that I'm able to launch IE browser but I'm not able to pass the url to it. I have tried many ways but I'm not able to get it done.

I have the given my code below. I have removed my erroneous syntax of passing the url to the browser. The below code would create the url and launch a blank IE explorer.

Please help me. Thanks in advance.

<html> 
<head> 
<script language="VBScript"> 

    Sub RunProgram
        callb = document.getElementById("callb").value
        call = document.getElementById("call").value
        url = "www.google.com"&callb&"and"&call
        msgbox(url)
        Set objShell = CreateObject("Wscript.Shell")
        objShell.Run "iexplore.exe"
    End Sub

</script> 
</head> 
<body>

<form style="width:254px; height:44px;">
CallB: <input type="text" id="callb" value=""><br>
Call  : <input type="text" id="call" value=""><br><br>
<button onclick="RunProgram">search</button>
</form>

</body>
</html>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can load a URL in the default browser by using the Run() method of WShell:

CreateObject("WScript.Shell").Run "www.google.com"

If you want to explicitly load the URL in Internet Explorer, you'll need to determine the full path to IEXPLORE.EXE first, then pass it to Run():

CreateObject("WScript.Shell").Run """" & strExePath & """ www.google.com"

Or

CreateObject("WScript.Shell").Run """" & strExePath & """ " & strURL

Note the quotes. You'll want to put quotes around the path to IE in case the path contains a space. In order to specify a quote within a string, you have to double it. If the quotes are confusing, you can use Chr(34) to specify a quote character:

CreateObject("WScript.Shell").Run Chr(34) & strExePath & Chr(34) & " " & strURL

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...