Jump to content

How to run a script file from a htm page?


Recommended Posts

Hi,

I DON'T ASK how to insert a script in a webpage (I already moreless figured that out).

What I would like to know is how to run a script that is not in the webpage but in a separate file (inthis case a .vbs file), by clicking on a link or a button.

Then how to open the htm file eventualy created by this script...

Thanks

Link to comment
Share on other sites


OK, the answer to your question is you cannot execute content on the client from within a browser without using ActiveX or Java if that is what you are asking. You did not specify whether the vbs was on the client or server. A VBS on the server generating web pages is ASP.

Exactly what are you trying to accomplish, It would help to have more detail in order to provide more appropriate answer.

Link to comment
Share on other sites

VBS on client side.

I'm trying to simply run a vbs file that I created myself and that is on the my computer, by clicking a link on the htm page that I also creted mysel and that is also in my computer, in the same directory as the vbs.

The reasons why I don't want to include the script in the page are that it's more convenient for me to edit scripts and htm pages separately, and that scripts are quiet long, that in the page there are other links that are simple and other that may require other scripts etc..

I would like also running the same script alone, from the vbs file, not in the htm file.

Link to comment
Share on other sites

So the HTM page is a launcher for other scripts? And you are just clicking the htm file to run, not using a webserver?

You CAN run external scripts with the src tag... Add src="<drive>:\<path>\file.vbs" in your <script> tag. There are limits on what you can run though, nothing that launches it's own windows will execute. Code that works with filesystem will prompt a warning but should execute OK. You should be able to run code that creates a htm page and then use

ie.navigate "newpage.htm"

to navigate to the new page. I have never seen anyone use a browser and scripts in quite this manner, but it should be possible.

If you can make the script do what you want while embedded in the HTML file it will work equally well in external file referenced through src="<file>"

here is simple external file code.

test.html

<HTML>
<HEAD>
<META HTTP-EQUIV="expires" CONTENT="0">
<TITLE>Test External VBS</TITLE>
</HEAD>
<BODY>
This is a external vbs script test...
<FORM NAME="Form1">
  <INPUT TYPE="Button" NAME="Button1" VALUE="Run">
  <script FOR="Button1" EVENT="onClick" LANGUAGE="VBScript" src="test.vbs"></SCRIPT>
</FORM>
</BODY>
</HTML>

test.vbs

msgbox "External Script test.vbs"

Edited by dman
Link to comment
Share on other sites

Hi! Thanks a Gb, dman, that's what I was looking for! :thumbup

I realised that for launching a script-created webpage it's better to embed the script into the page and even that, was not obvious.

But the code you gave me will be very useful for launching scripts that have nothing to do with htm page viewing, ironicaly...

(I'm one of the very rare scripter who use scripts for other use than server or ntwork.)

Because codes are long (more than 100 lines) I prefer to create a separate htm file with one script in it.

I then came with this solution:

<script LANGUAGE="VBScript"> 
<!--
sub window_onLoad()
'-----script that generates an htm page source-------
NewHtm = NewHtm & "<p>Hello World! " & Date & "</p>"
'-----end of script----
Document.Body.InnerHTML = NewHtm
end sub
-->
</SCRIPT>

Link to comment
Share on other sites

Glad I could help Fred.

You are right, script is useful for all kinds of desktop tasks. I usually do "scripting" tasks with simple visual foxpro programs (.prg files). VFP is perhaps the easiest and most powerful language ever created (you can tell I'm biased). VBS has great advantage though being preinstalled. :(

You also might want to try making a .HTA interface for your script launcher. gunsmokingman has lots of nice examples of this type of code.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...