I need to call a vbscript function from within an external javascript file :: function
heres what i got so far :
This function is not directly in the html page , its in an external js file , 'main.js'.
function createVBScript(){
var script=document.createElement('script');
script.type='text/vbscript';
script.src='vb/fldt.vbs';
document.getElementsByTagName('head')[0].appendChild(script);
}
the vbs file contains :
<开发者_开发知识库!-- // Visual basic helper required to detect Flash Player ActiveX control version information
Function VBGetSwfVer()
MsgBox "Hello there"
End Function
// -->
thats all i want to do for the time being. how do i call VBGetSwfVer() from main.js ?
This is a bad idea.
VBScript is only supported by IE; your page will never work on Firefox.
In Internet Explorer, you should be able to simply call the function like any other function.
However, you should port the function to Javascript instead.
All functions will be available in the global scope and so you can call them just as you would a regular javascript method.
An alternative method to include the vbscript is by using execScript
window.execScript('Class NixProxy\n' +
' Private m_parent, m_child, m_Auth\n' +
'\n' +
' Public Sub SetParent(obj, auth)\n' +
' If isEmpty(m_Auth) Then m_Auth = auth\n' +
' SET m_parent = obj\n' +
' End Sub\n' +
' Public Sub SetChild(obj)\n' +
' SET m_child = obj\n' +
' m_parent.ready()\n' +
' End Sub\n' +
'\n' +
' Public Sub SendToParent(data, auth)\n' +
' If m_Auth = auth Then m_parent.send(CStr(data))\n' +
' End Sub\n' +
' Public Sub SendToChild(data, auth)\n' +
' If m_Auth = auth Then m_child.send(CStr(data))\n' +
' End Sub\n' +
'End Class\n' +
'Function GetNixProxy()\n' +
' Set GetNixProxy = New NixProxy\n' +
'End Function\n', 'vbscript');
@slaks , before the vbsript ever gets called i have already determined the user agent. so yes it would never work in firefox , but it should never even be attempted if the end user has anything other than ie.
@sean , thats interesting , im gonna make reference of that.
my solution was :
include this in the header of the index.html
<script type="text/javascript" src="js/main.js"></script>
<script type="text/vbscript" src="vb/fldt.vbs"></script>
then , still in the index.html header , write a small inline javascript support function ,
<!--[if !IE]>-->
<script languge="javascript">
function jsCallToVB(i) {
var val = VBGetSwfVer(i);
return val;
}
</script>
<!--<![endif]-->
then in my external , main.js file , i call jsCallToVB(i);
精彩评论