Solved

Open a PowerPoint file using JavaScript

Posted on 2008-10-15
8
5,746 Views
Last Modified: 2012-05-05
I want a web page to open a PPS file using a JavaScript function.

The function is called launch PPT() and the function determines the name of the PPS file to open and then opens it.

I feel frustrated that I can't seem to see how to do it.  I've tried location.href("pptfile.pps"); and that works in internet explorer, but not in safari or firefox, and i want a method which will work in all three.

So basically i'm trying to replicate the operation of the HTML <A href=""> type anchor but in JavaScript. I can open the PPS files easily from such a link, I just can't seem to do the same in JavaScript and i'm not sure where I'm going wrong, or if I've just missed something obvious.

Thanks in advance.



0
Comment
Question by:najh
  • 4
  • 4
8 Comments
 
LVL 5

Expert Comment

by:nkoriginal
ID: 22722409
Try the code attached
<script language="JavaScript">

function startPowerPoint(strFile)

{

var myApp = new ActiveXObject("PowerPoint.Application");

if (myApp != null)

{

myApp.Visible = true;

myApp.Presentations.Open(strFile);

}

}

</script>
 

Then the link is:

javascript:startPowerPoint('http://servername/PowerPoint_files/template.PPT')

Open in new window

0
 
LVL 10

Author Comment

by:najh
ID: 22722536
No, that doesn't seem to work on  IE, Firefox or Safari unfortunately.  The link is a local file too - so no http:// type references.

My function is called launchPPT() which is already being called by something else (and that bit's working ok).  So the way I put your code in is as follows: [see code snippet]

(I get an "automation server can't create object" in IE and i get nothing in the other browsers).

I can't understand why it isn't possible to do a simple link like you can do in HTML, like this sort of thing:
<a href="pptfile.pps">my link</a> but have it activating of course.  It seems so strange.  I feel like I've missed somethine obvious.


    function launchPPT(){

      startPowerPoint("pptfile.pps"); 

    }
 

    function startPowerPoint(strFile){

      var myApp = new ActiveXObject("PowerPoint.Application");

      if (myApp != null){

        myApp.Visible = true;

        myApp.Presentations.Open(strFile);

      }

    }

Open in new window

0
 
LVL 5

Expert Comment

by:nkoriginal
ID: 22722736
Use this link

<a href="#" onClick="startPowerPoint();">Open my PPS</a>

and add this code to you html page between your <head></head tags.

Remember to change the strFile

<script language="JavaScript">

var strFile = "C:\\my folder\mypss.pps"

function startPowerPoint(strFile)

{

var myApp = new ActiveXObject("PowerPoint.Application");

if (myApp != null)

{

myApp.Visible = true;

myApp.Presentations.Open(strFile);

}

}
 
 

</script>	

Open in new window

0
 
LVL 10

Author Comment

by:najh
ID: 22722857
Sorry, that simply doesn't work.  

Just to be clear, the function MUST be called from my launchPPT() function, not from any extra <a> elements or anything like that.  It also cannot be a file which sits in a specified directory like that - it must work from the root of where ever i put it.  (so it should work from a CD, or a network drive, or a pen drive etc, just like the <a href="pptfile.pps"> does.)

It also must work on Safari and Firefox.

And besides, the function you've put in the <a> link doesn't have any arguments:
<a href="#" onClick="startPowerPoint();">Open my PPS</a>

when the function declaration requires an argument:
function startPowerPoint(strFile)
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 5

Expert Comment

by:nkoriginal
ID: 22722912
Sorry for my mistake.
Please paste your launchPPT code to see what you doing.
0
 
LVL 10

Author Comment

by:najh
ID: 22728902
I pasted it above - there's nothing in the function yet - it's there to hold all the code needed to launch the powerpoint file.  I just want to open it just like you can with an <a href="pptfile.pps">

I'm beginning to think that window.open(""); might be what i need to use.
0
 
LVL 5

Assisted Solution

by:nkoriginal
nkoriginal earned 100 total points
ID: 22730364
Try this:

<a href="javascript: void(0)"    onclick="window.open('http:/www.myserver.com/folderName/file.pps',   'windowname1',   'width=200, height=77');    return false;">Click here for simple popup window</a>
0
 
LVL 10

Accepted Solution

by:
najh earned 0 total points
ID: 22730754
nope that doesn't work, because it's not working from the launchPPT() function

I've got a solution of my own working now, but thanks for trying.

Here it is:


function launchPPT(){

  window.location = "pptfile.pps";

}

Open in new window

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

707 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

12 Experts available now in Live!

Get 1:1 Help Now