3

An old web application I recently have to work with is having an issue. There is an input element that contains the following:

onClick="javascript:Run('**SomeFilePath.mdb**');"

What this is supposed to do is open a users respective .mdb file.

First off, there is no javascript Run function defined anywhere. I searched online because I thought maybe it's an old javascript built-in, but I couldn't find anything.

Second off, there IS a vbscript Run() function, that implements the described behavior, defined in the source code, but as far as I know javascript can't call that other than via ajax, which as you can see isn't what is happening.

The strange part is this works for some users!

If anyone could shed some light as to why I'd appreciate it!

EDIT: The only browser I'm dealing with is IE. I know there is an active-x way to open a file, which is what the vbscript Run() function I mentioned above is using.

Update: So after more investigation/research, it would seem like when IE doesn't find the javascript Run() function it defaults to the vbscript Run() function that IS defined. However this only occurs on some versions of IE. Can anyone confirm this behavior?

Research links:

Comment referring to how IE defaults w/ scripting

Msdn article about using both script types in same page

Community
  • 1
  • 1
Andrew Hagner
  • 804
  • 1
  • 9
  • 18

1 Answers1

1

Yes, you can run vbscript from javascript and vice-versa, i do it sometimes when one language doesn't support something the other does. You can indicate in your script which is the default language in case you don't specify it like .

You can also specify it while calling the function like vbscript:functionname("..") or javascript:functionname("..")

As you noticed there are cases where the browser gets confused and doesn't find the function because he searches/executes the function in the wrong language. This behavior is influenced i suppose by version also but surely by in which order the logic flows in your script, if the browser first executes a javascript he tends to go further in this language in case of doubt. So to evade this

  1. don't mix the two unless realy necessary, translate your vbscript function in javascript)
  2. try to always use javascript, vbscript is less good at handling DOM etc
  3. in case they are mixed, specify the correct scriptlanguage when you call a function
  4. when opening a script tag, also give the correct language like or

So, specific, to solve your problem translate the vbsripts function to javascript and if not possible, call your function like onClick="vbscript:Run('**SomeFilePath.mdb**')"

peter
  • 41,770
  • 5
  • 64
  • 108