Solved

Open a PowerPoint file using JavaScript

Posted on 2008-10-15
8
6,243 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
[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
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
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 …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

691 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