Open ppt file in a new browser tab - javascript

A link that contains a .pdf such as the following opens in a new tab:
<a target="_blank" href="http://somePDF.pdf">Download</a>
Is it possible to make a Powerpoint file, .ppt, open in a new browser tab instead of making the user download the file?
I have tried this the following but this makes a user download the file:
<a target="_blank" href="http://somePPT.ppt">Download</a>
I am not sure if this is possible and have not been able to find any information on it so I am posting here.

If the user's browser isn't able to display the file and has no plugin that can display the file, it will offer the file as a download.
If you can export the PowerPoint slides to PDF or HTML, they are more likely to be displayed in the browser.

you could check if the browser has installed an pdf plugin, and if not use pdf.js to convert your pdf into an html page.
could look like this:
function hasPDFPlugin() {
for(var i = 0; i < navigator.plugins.length; i++) {
if(navigator.plugins[i].name.toLowerCase().indexOf('pdf') >== 0) {
return true;
}
}
return false;
}
if(!hasPDFPlugin()) {
// do the pdf.js stuff
}

with the help of google docs it can viewable.add file location after url=
https://docs.google.com/viewerng/viewer?url=
ex-https://docs.google.com/viewerng/viewer?url=http://example.in/filename.ppt

Related

Download html window object with JS

i have this iframe here, and i want to doanload the window page with pdf inside, js function print() only shows the page, i want to download it automatically, bellow is the full code (i tryed with jspdf too).
<iframe id="conteudoIframe" src="https://eproc.trf4.jus.br/eproc2trf4/controlador.php?acao=acessar_documento_publico&doc=41625504719486351366932807019&evento=20084&key=0562cc6eddee0cc4a81dd869f92328dceab34deeaa59f4a33c43da6361cf42d6&hash=08920b364dc8433ad071d6b10c7e3817" name="superior" width="100%" height="560px"></iframe>
<script>
downloadPdfFromIframe();
function downloadPdfFromIframe() {
var script = document.createElement('script');
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js';
document.head.appendChild(script);
script.onload = () => { setTimeout(download(), 20000); };
function download() {
var myIframe = document.getElementById("conteudoIframe").contentWindow;
myIframe.focus();
myIframe.print();
myIframe.close();
var pdf = new jsPDF();
pdf.fromHTML(myIframe);
pdf.save('test.pdf');
return false;
}
}
</script>
Iframes are only a window to remote objects thus while viewing they are showing both the already downloaded html surround and the already downloaded PDF but the PDF is independent It may be downloaded before or after the frame, you can see the pdf behind the print html dialog. So the PDF is in a different application as seen in the second browser view of your HTML.
Thus you have to save/print either one at a time. Frame object or Pdf object, to get both is not impossible, just needs to be done with a suitable application (not browser). So just like here I have ScreenShots, those canvases can be easily saved or printed as PDF.
A Chrome based Browser viewing the iFrame for printing
A Firefox based Browser viewing the iFrame to print using any other method like open in a second application window.
If you need to download the two parts outside a browser then use two Download Commands so here is my.pdf
curl -o my.pdf "https://eproc.trf4.jus.br/eproc2trf4/controlador.php?acao=acessar_documento_implementacao&doc=41625504719486351366932807019&evento=20084&key=0562cc6eddee0cc4a81dd869f92328dceab34deeaa59f4a33c43da6361cf42d6&hash=08920b364dc8433ad071d6b10c7e3817&termosPesquisados="

How can I open a link in Chrome from Photoshop to download an image?

I'm creating a script in Photoshop using JavaScript that I want to open chrome for all types of windows users and open a link in chrome. After the chrome is open and link is insert I want to complete a form with values that I know and submit the form, the new link that is generated I want to open and download the image.
Using my code the error I received on Photoshop is "the window is undefined", but if I delete window.open line the chrome open using the script in Photoshop.
Here is my code. Any solutions?
var commandtoRun = "C:\\PROGRA~1\\Google\\Chrome\\Application\\chrome.exe";
app.system(commandtoRun,"","","open","1");
var windowObjectReference;
window.open(
"https://www.yourURL.com", "_blank");
I did it with
window.onload = function() {
window.open("https://www.w3schools.com");
}
//openRequestedPopup();
//file.remove();
var site="//mylinkwithform"; //your side
if ( $.os.indexOf("Windows") != -1 )
{//SYSTEM IS ONE OF THE WINDOWS
app.system("cmd.exe /c\"start http://"+site+"\"" );
}
else{//MUST BE MAC
system.callSystem("open http://"+site);
}
How i insert the values in the form from the site and submit the form?

Files encoding isse in chrome only

I have different links which opens another page in a popup.The popup function is like this.
function popUp(URL) {
eval("lesson = window.open(URL, 'lesson', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600,left = 250,top = 50');");
}
When links are opened,its working fine in mozilla.When links are opened in chrome its giving me the following content
The filename has spaces.I dont if this is happening because of this space or not because I am not able to rename or upload the files into that server

Javascript: Clicking Link to Download pdf

I am working on a JS program which should open a webpage www.mysite.com & click on a link inside that webpage to download a pdf.
The link to click looks like this:
<a onclick="download();return false;" href="#noWhere">Click to Download</a>
Ordinarily, manually clicking the link, calls the following function to download the pdf:
function download() {
document.forms[0].action = path + "/xxW04_sv_0140Action.do";
document.forms[0].target = "_self";
document.forms[0].submit();
}
My code is simplified javascript code to open the page & click on the "Click to Download" button is this:
<script>
var linkname = "http://www.mysite.com";
var windowname = "window_1"
// Opens a new window
var myWindow = window.open(linkname, windowname ,"width=400,height=600");
//should open a link to download pdf
myWindow.document.getElementById('href = \"#noWhere\"').click();
</script>
So far I can open the webpage "mysite.com" in a seperate window using but for some reason no button clicking is happening and certainly no pdf is downloaded.
Of course if I manually click the "Click to Download" button it downloads.
Can anyone tell me what i'm doing wrong? Why I cannot simulate a click with the above js code?
Or possibly give me some things to try. Any help much appreciated and Than you.
UPDATE:
From the initial answers below, possibly this method is doomed for failure! Can anyone suggest a better way I could be downloading these pdfs?
You'd better use:
<a href="http://www.mysite.com/mypdf.pdf">
This should download that pdf file.
It won't work. The same-origin policy will prevent you from accessing the content of any pages loaded from another domain.
Also, as #kamilkp pointed out, you have to provide the getElementById() function with an id value. You can't just plug any old stuff in there and expect it to work.
Another problem is your reliance on clicks for this to work. What about users that use the tab key to select links and then press Enter to follow the link?

forcing a pdf to download when clicked on button

I hava a backbonejs view containing a button saying "download pdf". I also have the url available where the pdf can be found. I want that when user clicks on the button, the pdf file gets downloaded. Is it possible?
EDIT: My view code in backbone.js
savendownload: function () {
this.$("#saveanddownload").button('loading');
var that = this;
var formData = this.fetchData();
if (formData) window.invoices.create({
buyer: formData.buyer,
items: formData.items,
company: formData.company,
action: "savendownload"
}, {
wait: true,
success: function (model) {
var data = model.toJSON();
var filename = data.filename;
//download code here
}
});
}
Don't use a button, use a link and set the href attribute to the URL of your PDF file. The browser will handle the file download for you, honoring the user's browser preferences.
<a href="your/file.pdf" />
If you need the link to look like a button, you can style it using CSS. See for example this SO thread.
Edit: AFAIK, you can't reliably initialize a file download from javascript. What you can do is to open a new window/tab with your pdf URL:
window.open("http://domain.com/document.pdf",'_blank');
But the user's browser can block the new window from being created. You might want to simply generate a download link:
$('<a>Click here to download PDF</a>').attr('href', filename).appendTo(that.$el);
And have the user click the link to initiate the file download.
use the "download" tag
<a href="assets/pdfs/yourdocument.pdf" download>Download PDF</a>
but does not wok at IE Explorer ;)

Categories