Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Open a PowerPoint file using JavaScript

Posted on 2008-10-15
8
Medium Priority
?
6,600 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

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!

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

604 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