I need to allow users to click a link to a .bat file on an IIS 6.0 server directory and view that file as plain text. I have set the MIME type for .bat file to "text/plain." This works perfectly in both Chrome and Firefox. The way this works is that I have a button that launches a separate popup browser window to the .bat file. Example is below:
onclick=\"window.open(\'\/eemcontrolpanel\/jobs\/" + encodedFileName +"\',\'popUpWindow\',\'height=500,width=400,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes\');\">View Script</button>").scrollHeight;
As I said, this works in both Chrome and Firefox, but for some reason, IE 8 immediately closes the popup and asks me if I want to Run or Save the file.
I think IE goes by filename extension to detect its an executable file. Maybe you could give it another name by adding a header like:
'Content-Disposition: attachment; filename="thebat.txt"'
Related
I've a shared directory reachable by html page in this way
<div onclick="windows.open('file://mypath/mysharefolder','_blank');">Shared folder</div>
This works with internet explorer, but not with Chrome browser (error: Not allowed to load local resource).
So I've thought of replacing the link with a tag to allow the download of a lnk file (created manually) containing the path of the shared directory like this
<a href="mylinktofolder.lnk" download>Shared folder</a>
this tag works to download other kind of file (img,pdf,...), but not with lnk file; download in Chrome fails because doesn't find file mylinktofolder.download.
Is it possible to download such a file?
Thanks in advance
Chrome marks .lnk files as unsafe for download so you won't be able to workaround this using html/js unfortunately
Sources:
https://stackoverflow.com/questions/55177641/lnk-file-downloading-as-download-in-chrome-and-it-failed-to-download-in-first\
https://stackoverflow.com/a/34890432/2491027
Is it possible to download such a file?
Yes, sort off, here I show two tabs but the second is as you described a shared folder that was opened as second tab, however, has been torn off to show the two types of links in the first index.html
So to answer your question the second link tested with a range of LNK files lastly to a cmd.exe.lnk and onclick triggers a lnk download but as normal for windows the .lnk extension is not shown as actioned, so if the lnk is
a file like svg.lnk it will open the linked svg in the second tab.
a lnk to a folder it will open the folder
a lnk to a command it in turn forces cmd.exe to be downloaded with a warning
and you can accept (keep) and run that copy of cmd !
All the above is possible using Chrome based browsers such as Edge or SlimJet or Ungoogled Chrome. and Chrome too.
<div onclick="window.open('file://c:/mysharedfolder','_blank');">Shared folder</div>
<div onclick="window.open('file://C:/myshortcuts/downloads.lnk','_blank');">downloads.lnk</div>
.
As non admin user I can navigate to local shares or remoteshares or remote mapped drives without any authorisation, other than I have user read write permission for all those locations.
<div onclick="window.open('file://C:/TEMP/HTA/share(local).lnk','_blank');">Local Shared folder</div>
I have a PHP web application in which users can click a button to download an XML file generated on the fly. It has worked well for a long time, but suddenly I am getting bug reports from a single Internet Explorer user (I only have a screenshot showing the bug). I need your help to figure out possible causes.
First, the button click in the web GUI is handled with jQuery which has a JavaScript window.location statement:
$("#generate-button").click(function() {
...
window.location = "generateXml.phtml";
}
generateXml.phtml is PHP which creates an XML string which is returned:
header('Content-Type: application/xml');
header('Content-Disposition: attachment; filename=xmlFile.xml');
echo $xmlString;
Up until now, users have always been prompted whether to open or save the xmlFile.xml (which is correct). Now however, a user of Internet Explorer (version unknown but it appears to be IE10) is prompted whether to open or save generateXml_phtml:
Note that IE has replaced the . (dot) with _ (underscore). It seems the PHP server code in generateXml.phtml is not even executed.
Do you have any ideas? I cannot replicate the bug using IE on my own system.
Can you give a direct link to the problem? Try change the extenssion to .php its weird if the file insĀ“t being processed the web server should only give you a executed code not the raw code, maybe is something wrong with .phtml extenssion...
Given a URL like: http:// host:port/app/whatever.js
IE(Internet Explorer) attempts to download whatever.js, instead of rendering(or executing) it on the browser. I am using IE8/WinXP
How can i make IE render(/execute) the .js instead (of prompting for a download)?
(On FireFox/Chrome whatever.js is rendered correctly, but not in IE.)
I realized that the behavior that IE is exhibiting is correct - thats the default behavior. IE will prompt for .js file to be downloaded if you give URL of .js directly in the browser bar.
But if the .js is invoked via HTML
<script src="whatever.js"> tag,
then the JavaScript is executed.
Therefore, there isn't really a case for .js to be rendered.
I have a "Download file" href defined in my javascript file as:
$("#downloadTag").html("Download");
In chrome it works as expected i.e. when I click on this download link it gives file name as "download.csv". However, in firefox, it puts some gibberish name like "puzdb.part".
Could someone please point me what I am doing wrong?
Thanks
Edit:
Here is the jsfiddle demo: http://jsfiddle.net/kLJz9/
Edit #2:
I noticed that on windows it does not put .csv extension for chrome as well and behavior for firefox is still same (i.e. .part extension)
For Chrome you can designate the file name/extension by adding a download attribute to your anchor tag.
Download
This attribute only works in chrome v 14+ and no other browser.
I am also looking for a solution to this problem, but I hope this helps.
EDIT:
the download attribute should fix the issue you are having on windows machines and chrome.
Saw a similar question at Download a file using Javascript but this one is specific to IE and I'm using extjs and alfresco (opsoro). I can get a download prompt for text files fine in Opera, Chrome, and Firefox, but not IE.
Below is a list of what I've tried so far, which all work on other browsers except IE7.
document.location = downloadLocation;
window.open(downloadLocation,'Download');
location.href = downloadLocation;
When downloading other mimetypes (csv, xls), they download fine using any of the methods mentioned above.
You may need some help from the backend. Instead of serving the file statically, the backend app can load and serve the file contents with a content disposition header. That is guaranteed to invoke a download.
Content-disposition: attachment; filename=hello.txt
I don't know how you could do it with Alfresco, though.
Edit: Wait! Check this out: http://forums.alfresco.com/en/viewtopic.php?f=36&t=21356&p=70252