Solved

Open a PowerPoint file using JavaScript

Posted on 2008-10-15
8
5,907 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 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