Open a PowerPoint file using JavaScript

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.



LVL 10
najhAsked:
Who is Participating?
 
najhConnect With a Mentor Author Commented:
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
 
nkoriginalCommented:
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
 
najhAuthor Commented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
nkoriginalCommented:
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
 
najhAuthor Commented:
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
 
nkoriginalCommented:
Sorry for my mistake.
Please paste your launchPPT code to see what you doing.
0
 
najhAuthor Commented:
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
 
nkoriginalConnect With a Mentor Commented:
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
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.

All Courses

From novice to tech pro — start learning today.