?
Solved

JavaScript equivalent to Server.CreateObject on *client* side

Posted on 2004-08-25
19
Medium Priority
?
1,426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 800 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
 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

649 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