Solved

JavaScript equivalent to Server.CreateObject on *client* side

Posted on 2004-08-25
19
1,286 Views
Last Modified: 2013-11-19
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
Comment
Question by:DalTXColtsFan
  • 5
  • 4
  • 4
  • +4
19 Comments
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 11896373
VBSCRIPT would be your opton...

~Hemanth
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 11896386
> VBSCRIPT would be your opton...
This is the object that would be used .... new ActiveXObject("Shell.Application")
0
 
LVL 2

Author Comment

by:DalTXColtsFan
ID: 11896730
Is ActiveXObject a JavaScript command or a VBScript command?
0
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 11896844
vbscript !
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 11897398
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
 
LVL 13

Expert Comment

by:StormyWaters
ID: 11897742
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 11897895
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
 
LVL 15

Accepted Solution

by:
VincentPuglia earned 200 total points
ID: 11898538
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 11900002
The xls files are stored on web server in database records as BLOBs, right?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 2

Author Comment

by:DalTXColtsFan
ID: 11904919
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
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 11906763
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
 
LVL 2

Author Comment

by:DalTXColtsFan
ID: 11907000
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
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 11907113
Joe,

My mistake... Instead of New ActiveXObject... try using server.CreateObject...(this is vbscript and other one is JScript)
0
 
LVL 2

Author Comment

by:DalTXColtsFan
ID: 11907151
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
 
LVL 15

Expert Comment

by:justinbillig
ID: 11907298
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
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 11907336
Since the context is server.. I don't think it can !

0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 11909024
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
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 12301399
Hi Venabili,

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

Vinny
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Auto Submit on dropdown box 19 35
angularls and plnkr 14 19
Hidden Field Value 10 37
Jquery autocomplete 10 30
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now