0

I have a problem with embedding a VBScript to my Javascript in a .js file. I want to place a title to my alert boxes, so I want to use the VBScript.

I have a .js file, and this is what I want to insert in my .js file.

<script language="VBScript">
Function makeMsgBox(tit, mess, icon, buts, defs, mode)
    butVal = icon + buts + defs + mode
    makeMsgBox = MsgBox(mess, butVal, tit)
End Function
</script>

But it gives me an error, I think it does not allow me to insert a VBScript in my Javascript file.

1
  • 1
    I suppose you could try to generate the script tag and contents for the VBScript with Javascript, but why not just put it in it's own file with the appropriate filetype? You could of course use something like a jQuery Dialog instead, which would probably be preferable. Commented Dec 19, 2011 at 2:40

2 Answers 2

2

You cannot have the script declaration <script language="VBScript"> in a .js file. You also cannot have a VBScript function in a .js file.

You can try creating a .wsf file within which you can use both JavaScript an VBScript.

I am not clear about what all the parameters in your function are doing but here's how you can use both JavaScript and VBScript in the same Windows Script File and even call each other's functions:

<?xml version="1.0" ?>

<package>
    <job>   
        <script language="VBScript">        
            Function makeMsgBox(tit,mess,buts)
                makeMsgBox = MsgBox (mess,buts,tit)
            End Function
        </script>   

        <script language="JavaScript">
            var YES_NO_CANCEL = 3;
            makeMsgBox("VBScript message box", "Calling from JavaScript", YES_NO_CANCEL);
        </script>
    </job>
</package>
Sign up to request clarification or add additional context in comments.

15 Comments

Hi, thank you @Abbas, its working already i can set title already but the VBScript is always present at the title bar.. is there a way to remove it?
The title bar could say: "VBScript:Hello there" can I make it to just "Hello"?
I am sorry, I don't understand. Are you saying that your .js file with a VB function working? In case it is, can show what you have written in that file?
@Abbas - The reason tinks is using VBScript is because (I suppose in IE) it allows him to set a MsgBox window handle title text.
@Abbas thank you. I found another alternative though.. abeautifulsite.net/blog/2008/12/jquery-alert-dialogs - using jQuery.
|
0

You can't include VBScript inside your .js file. You have to add this script inside your html code.

<script type="text/vbscript" >
set objSHL=createobject("wscript.shell") 
strMsg= objSHL.popup("message",timetoclose,"title",icon)
</script>

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.