• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1602
  • Last Modified:

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
0
DalTXColtsFan
Asked:
DalTXColtsFan
  • 5
  • 4
  • 4
  • +4
1 Solution
 
HemanthaKumarCommented:
VBSCRIPT would be your opton...

~Hemanth
0
 
HemanthaKumarCommented:
> VBSCRIPT would be your opton...
This is the object that would be used .... new ActiveXObject("Shell.Application")
0
 
DalTXColtsFanAuthor Commented:
Is ActiveXObject a JavaScript command or a VBScript command?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
HemanthaKumarCommented:
vbscript !
0
 
RanjeetRainCommented:
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.
0
 
StormyWatersCommented:
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.
0
 
ZvonkoSystems architectCommented:
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.
0
 
VincentPugliaCommented:
Hi,

Is this what you want?

<html>
<script language='javascript' type='text/javascript'>

function getExcel(theSheet)
{
    var theApp = new ActiveXObject("Excel.Application");
    if (theApp != null)
    {
      theApp.Visible = true;
      theApp.Workbooks.Open(theSheet);
    }
  }
</script>
<body>
<a href="javascript:getExcel('absolutePath/filename.xls')">filename.xls</a>.
</body>
</html>


Vinny
0
 
ZvonkoSystems architectCommented:
The xls files are stored on web server in database records as BLOBs, right?
0
 
DalTXColtsFanAuthor Commented:
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
0
 
VincentPugliaCommented:
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
0
 
DalTXColtsFanAuthor Commented:
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!!!!!!!!!
0
 
HemanthaKumarCommented:
Joe,

My mistake... Instead of New ActiveXObject... try using server.CreateObject...(this is vbscript and other one is JScript)
0
 
DalTXColtsFanAuthor Commented:
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
0
 
justinbilligCommented:
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? )
0
 
HemanthaKumarCommented:
Since the context is server.. I don't think it can !

0
 
VincentPugliaCommented:
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
0
 
VincentPugliaCommented:
Hi Venabili,

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

Vinny
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

  • 5
  • 4
  • 4
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now