Link to home
Start Free TrialLog in
Avatar of DalTXColtsFan
DalTXColtsFan

asked on

JavaScript equivalent to Server.CreateObject on *client* side

Greetings experts,

How could I use JavaScript to launch, for example, Microsoft Excel or any other application that supports OLE Automation on the *client* machine?  Basically, the equivalent of Visual Basic's CreateObject command, but I want the application launched on the client.

In this specific example, I have an ASP application hitting a database that has files created by an OLE application saved as BLOBs, and I want to allow the ASP user to click a link, launch the app on their PC and open the file.

Can I do this with JavaScript?

Thanks
Joe
Avatar of HemanthaKumar
HemanthaKumar

VBSCRIPT would be your opton...

~Hemanth
> VBSCRIPT would be your opton...
This is the object that would be used .... new ActiveXObject("Shell.Application")
Avatar of DalTXColtsFan

ASKER

Is ActiveXObject a JavaScript command or a VBScript command?
vbscript !
Hey, isn't there an EMBED tag in HTML???

The same functionality is also provided by OBJECT tag.

I can't think of a more neat way of doing it.
ActiveX would, of course, only work with the proper security settings. And only on Internet Explorer. So it would only be really feasible for an intranet application.
And, IIRC (since I don't use ActiveX ever),
new ActiveXObject("Shell.Application") is Javascript,
CreateObject("Shell.Application") is vbscript.
I could be wrong about this.
Avatar of Zvonko
Hello buddies ;-)

Hi Joe,
you need not to do anything on client side.
Simply extract the xsl files from the BLOB to your server directory and propose to the browser a link on the page to those xsl file.
The user can now click on the link and is asked wether he want to download the xsl file or to open it with his Excel application. That's all.
ASKER CERTIFIED SOLUTION
Avatar of VincentPuglia
VincentPuglia

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The xls files are stored on web server in database records as BLOBs, right?
I decided to boost the points here because it looks like I have a bigger problem than I thought.

I'm modifying an ASP application that uses a mix of ASP, VBScript and JavaScript.  I was tasked with adding a menu item that when clicked would open the application on the client and have the application open the current file from the database (the app has its own OLE Automation method for opening a file from the database).

Here is my the code that adds the menu item (link) to the page:

      <TD>
          <TABLE border=0 cellPadding=0 cellSpacing=0 width="100%" class="MNLevel2Row">
             <TR valign="center" onclick="javascript:OpenPog('17')">
                    <TD class="MNLevel2Item">Open in Space Planning</TD>
             <TD>&nbsp;&nbsp;&nbsp;</TD>
             </TR></TABLE>
      </TD>

A whole bunch of other functions are called from this page that are #included in another file.  The top of the file includes this line:

<%@ CodePage=65001 Language="VBScript"%>

but most of the functions *on* the page are clearly JavaScript, not VBScript, for example:

Sub GoStr(variUserID)
      parent.frames.item(0).document.all.item("pagedesc").innertext = "<%=Resource1020%>"
      parent.frames.item(1).location.href = "NavBar.asp?UserID=" & variUserID
      parent.frames.item(2).location.href = "Objsel.asp?UserID=" & variUserID
End Sub

so I added my function to this page.  Here is my code:

Sub OpenPog(varCurrentFileDBKey)
      alert("try")
      var objPSApp = new ActiveXObject("MyOLEServer.Application")
      objPSApp.Visible = True
                objPSApp.LoadFileFromDatabase(varCurrentFileDBKey)
End Sub

If I comment out the lines after the alert call and click the link, I see the try messagebox.  If I uncomment those lines, I get "Error:  Expected end of statement".

What am I up against here?  I tried putting semicolons at the ends of the lines but it gave me a syntax error.

Thanks
Joe
Hi Joe,

'Sub' is not javascript; javascript is c-like, requiring function keyword & braces:

function OpenPog(varCurrentFileDBKey)
{
     alert("try")
     var objPSApp = new ActiveXObject("MyOLEServer.Application")
     objPSApp.Visible = True
     objPSApp.LoadFileFromDatabase(varCurrentFileDBKey)
}

see the code I posted above.

Vinny
Vinny,

I tried it that way and got an invalid character error.

This is what's confusing me.

From the HTML generated by the ASP:

javascript:GoPlan('819199','1','17')

Yet in the ASP page containing the function GoPlnStatus:

<%@ CodePage=65001 Language="VBScript"%>
<!-- #include file="Net_Res_Strings.asp" -->

Sub OpenPog(niPogDBKey)
      alert("try")
      var objPSApp = new ActiveXObject("ProSpace.Application")
      objPSApp.Visible = True
End Sub

Sub GoPlan(variUserID, variDBStoreKey, variDBPlanogramKey)
      parent.frames.item(0).document.all.item("pagedesc").innertext = "<%=Resource1022%>"
      'parent.frames.item(1).location.href = "Left_NavBar.asp?UserID=" & variUserID & "&DBStoreKey=" & variDBStoreKey & "&DBPlanogramKey=" & variDBPlanogramKey
      parent.frames.item(2).location.href = "PlnStatus.asp?UserID=" & variUserID & "&DBStoreKey=" & variDBStoreKey & "&DBPlanogramKey=" & variDBPlanogramKey
End Sub

So the calling HTML says javascript, but the script language in the file is VBScript and there are Sub keywords, no braces and no semicolons.

Yet keywords like parent.frames.item etc - those are exclusively javascript aren't they?  And isn't alert a javascript-only keyword?  I tried using MessageBox there and it didn't display the messagebox.  Didn't throw an error though.

Help me somebody, please - I'm horribly confused!!!!!!!!!
Joe,

My mistake... Instead of New ActiveXObject... try using server.CreateObject...(this is vbscript and other one is JScript)
But won't Server.CreateObject create the object on the server, not the client?  I want the object created on the client, using client resources.

Thanks
Joe
Then you could either a make an ActiveXObject in javascript, but ( as posted before ) you have to worry about browser security and what not ...

or you could use CreateObject in vbscript , but i do belive the same security issues come into effect ( or is it affect? )
Since the context is server.. I don't think it can !

Hi Joe,

 Are you saying that you wrote the function as a javascript function (complete with <script...> tags, and that the ASP is changing it to vbScript??????  Or, are you saying someone else wrote the routine as vbscript?  

  Cut & paste the code I provided, and embed it within <script..> tags (as demonstrated above)

 parent.frames.item  is part of the DOM (document object model), and as such is part of HTML, not javascript, not vbscript, not asp -- though all three can manipulate it.

Regarding the invalid character code message -- which line and what does it say exactly?  Sometimes there is a null character being interpreted; try deleting the line and rewriting it.

Vinny
Hi Venabili,

   Whatever you decide is fine by me (though I suspect he found the errant character and thus solved his problem)

Vinny