View local html file with .asp extension in browser - html

Hi I have crawled a website for offline view, but many pages are downloaded and saved as .asp and there are links that point to these pages. But when I open these html page that has .asp extension in Chrome browser, the chrome will download the page instead of rendering the page. Is there a way to set the chrome to render the page instead of downloading it ?
Thanks

Chromium uses the system mime-type for the local files. On Linux you can change it in the xdg-open configuration:
$ mkdir -p ~/.local/share/mime/packages
$ cd ~/.local/share/mime/packages
$ touch application-x-asp.xml
Then edit the ~/.local/share/mime/packages/application-x-asp.xml:
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="text/html">
<comment>Active Server Page</comment>
<icon name="text-html"/>
<glob-deleteall/>
<glob pattern="*.asp"/>
</mime-type>
</mime-info>
to set up the mime-type to text/html. On te end you have to logout/-in again, or just run:
$ update-desktop-database ~/.local/share/applications
$ update-mime-database ~/.local/share/mime

When your browser opens a file it uses the MIME type to decide which action it should take, typically download or open in the bowser.
So, for example, it encounters a zip file it will open the file save dialogue box and allow you to save the file.
And, if for example, you request a .asp from your browser which is served from a web server the browser will use the MIME type to decide which action to take, which will be to display in the browser.
The MIME type will be sent within the http headers and this would not be sent to the browser when you open your off-line .asp pages.
So if you could change the MIME type to "text/html" for .asp it should open it in the browser.
Unfortunately, there does not seem to be an option for changing MIME type / actions in Chrome.
You can change these setting in Firefox within Tools > Options > Content > FileTypes > Manage..

There is a way to open local, .asp files as HTML in Firefox.
Find your Firefox profile folder. On Windows 7, I found it here:
C:\Users\user\AppData\Roaming\Mozilla\Firefox\Profiles\738xdie.default\mimeTypes.rdf
Then add these lines to mimeTypes.rdf
<RDF:Description RDF:about="urn:mimetype:text/html"
NC:fileExtensions="asp"
NC:description="ASP Pages"
NC:value="text/html"
NC:editable="true">
</RDF:Description>
Restart browser. Your local file will now render as HTML.
There may be a similar technique with Chrome.

I suppose you want to view downloaded pages directly, that is not via some local web-server. Then I'd suggest to change (or append) file extensions during download according to their reported content-types from response headers. Of course, this will require to adjust all links to changed filenames inside other files. The other approach could be to store content-type of each page in a meta-base, and using a local web-server to serve the files according to their actual types from the base, not file extensions.

I have two solutions for you. the first one is to open those files with firefox.. and that's it..
if you insist to open them with chrome. you have to change all files extension to html instead of asp. use some programs for renaming..
but the links will be broken between pages..
so you have to find the js file that all pages use add this code in it to fix the links
document.body.addEventListener('click',function(e){
if(e.target.nodeName=='A'){
e.preventDefault()
href=e.target.href.split('/')
href[href.length-1]=href[href.length-1].replace('.asp','.html')
href=href.join('/')
parent.location=href
}
})
})

Related

PDF file not downloading with HTML5 download attribute

I have a download attribute on two different anchor tags. One is for an Excel file and one for PDF. The Excel file downloads. The PDF opens in new tab instead. Why is this happening? Code below:
<div class="col-2 center">
<a download href="files/excel-sample.xlsx">
<img src="img/excel-logo.png" />
</a>
</div>
<div class="col-2 center">
<a download href="files/pdf-sample.pdf">
<img src="img/pdf-logo.png" />
</a>
</div>
Download Basics
So essentially what is happening is that when you link to a file URL, the browser opens that URL and if it has accessibility to display the content, it almost always will. Some most common examples of this are image files (.png, .jpg, etc...). However, if the browser can't read the file type (.zip) then it will almost always download the content. A great way to force the browser to download the file is by adding the download attribute in the <a> tag.
PDFs are readable and accessible by most modern browsers so by default, the browser is set to open the file instead of download it. Because of this accessibility, most modern browsers have introduced settings that allow users to decide on a machine by machine basis whether or not a PDF (or any other readable file) should open in another window or download by default. In many cases, even with the download attribute, the browser can still decide for itself how to handle the file.
Possible Solutions
1 - If you are just trying to achieve the download functionality on your browser only (which it looks like you aren't but I thought I should include anyway), you can open chrome, go to Settings -> Advanced Settings -> Content Settings -> PDF Documents -> Toggle on Download
2 - You can compress and zip the file so the browser is forced to download the file.
3 - If you have root server access to your site and it is using Apache, you can add the following to your .htaccess
ForceType application/octet-stream
Header set Content-Disposition attachment
If you are using an NGINX web server, you can add the following redirect
location ~* (.*\.pdf) {
types { application/octet-stream .pdf; }
default_type application/octet-stream;
}
So the solution is:
<a href="pdf-sample" download="pdf-samle.pdf">
Note that "href" has a value without the .pdf reduction, but "download" has a value with the .pdf reduction. Remember you also have to remove the .pdf reduction from the targeted file. As it seems the browser treats the downloaded file as a non pdf file and therefore is not opening it by default.
you cannot use <a download href="files/pdf-sample.pdf">
but you can use <a href="files/pdf-sample.pdf"> for preview your file

Which file types can be viewed in browser (inline, without a plugin)

I just want to know which file types (like .png, .pdf, .txt) can be viewed in browser (like Chrome, Firefox). Because sometimes when i click on file link, instead of displaying in browser it download automatically. Why this happens ? Below is my code. Any help will be appreciated.
<script>
function openPDF(url){
var w=window.open(url, '_blank');
w.focus();
}
</script>
<a href="burger1.jpg" target='_blank'>link</a>
<div onclick="openPDF('1.pdf');">PDF 1</div>
It indeed depends on several factors:
the server response Content-Disposition header value inline (open it) vs attachment
(classic download)
the browser configuration (how to behave for various file types)
installed browser plugins
the ability of the browser to open the file
A detailed technical explanation can be found here: https://superuser.com/questions/1277819/why-does-chrome-sometimes-download-a-pdf-instead-of-opening-it
For example Firefox can open most PDF files (but generally not advanced forms, encrypted files ...),
https://support.mozilla.org/en-US/kb/view-pdf-files-firefox
https://support.google.com/chrome/answer/6213030?hl=en
https://helpx.adobe.com/lu_en/acrobat/kb/open-in-acrobat-reader-from-chrome.html
https://www.investintech.com/resources/blog/archives/3684-view-pdf-files-mozilla-firefox.html (about browser PDF reading)
Most advanced PDF features will require the user of Acrobat Reader or a special Acrobat Reader plugin.
There are two aspects to this issue.
There are addons you can add on to the browsers to allow viewing virtually anything in the browser window. In the case of PDF, for instance Firefox can't show those by default, but you can install an addon. Or, there are standalone PDF viewers that also come with such an add-on which you can activate if desired.
And when you've done that, as noticed in the comments, if the resource is marked as download, the browser will download it instead of trying to open it, no matter the file type.
Ditto if it has a http header of Content-Disposition: attachment.
So don't use that.
In normal cases, following files can be viewed in browser.
.PNG
.JPEG
.PDF
.doc
etc ...
and following files will always be download.
.zip
.exe
etc ...
But in special cases, it depends on user browser settings and preference. You can get further details from this link.

Open file on a local network using html a href "file:\\" Not allowed using link

I am trying to display a document in the browser using a html link which has this form :
filename.pdf
I already tried to use file:// , file:/// , file:\\ , and file:\\\ , but I always have the same error :
Not allowed to load local resource: file://...etc
The strange thing is that it is working on one computer (with google chrome) when the extention "LocalLinks" is installed but not on the others computers (with the same extention installed).
It is working on all computers when I directly paste the file path in the URL, the only problem is when using the link to open it.
I don't understand the issue.
Your Best bet would be to store it in a folder relative to the served HTML file. Because different Web Browser's use different protocols.
Here are some other more in depth answers:
How can I create a link to a local file on a locally-run web page?

Can't get simple html5 manifest cache to work!

I'm trying to get a simple html5 webcache to work.
This is my one and only html page, index.html:
<!DOCTYPE HTML>
<html manifest="./main.manifest">
<body>
<p>Hi.</p>
</body>
</html>
This is my only cache file, main.manifest:
CACHE MANIFEST
# 2011-05-02-03
index.html
I'm running on apache shared hosting, I put a .htaccess file in my web directory where these other two files are, because I thought maybe I have to define the mime type:
AddType text/cache-manifest .manifest
So in the end I just have these three files in that directory:
index.html
main.manifest
.htaccess
When I visit the page on chrome from my mac, safari from my iphone, or chrome from my android 2.3 device, nothing happens, the page just loads as usual. If I turn airplane mode on (killing all connections) the page can't be loaded (so I guess caching failed).
What am I missing here?
Thanks
------------ Update ------------------
I think the mime type was not being recognized correctly. I updated .htaccess to:
AddType text/cache-manifest manifest
Now if I run in google chrome with console on, I see:
Document was loaded from Application Cache with manifest
http://example.com/foo/main.manifest
Application Cache Checking event
Application Cache NoUpdate event
Firefox prompts me when I load the page about the website wanting to let me store it to disk, so that's good. Looks like it's also working on android 2.3.4. The browser still says "This page cannot be loaded because you are not connected to the internet", but then it loads anyway.
Thanks!
First, you were right the first time on your mime type declaration. It should be like this:
AddType text/cache-manifest .manifest
Next, read this paragraph from Dive Into HTML5:
Q: Do I need to list my HTML pages in my cache manifest?
A: Yes and no. If your entire web application is contained in a single
page, just make sure that page points to the cache manifest using the
manifest attribute. When you navigate to an HTML page with a manifest
attribute, the page itself is assumed to be part of the web
application, so you don’t need to list it in the manifest file itself.
However, if your web application spans multiple pages, you should list
all of the HTML pages in the manifest file, otherwise the browser
would not know that there are other HTML pages that need to be
downloaded and cached.
So, in this case, you don't need a cache manifest. The browser will automatically cache your page (as long as it's the only resource, such as a CSS file or Javascript file, for example).
For more information, visit the link above.
I have had some trouble using "explicitly cached" items in my manifests, so I usually set it up like this:
CACHE MANIFEST
# 2011-05-02-03
CACHE:
index.html
But the other answer is correct, the browser will automatically cache any URLs that include an application cache manifest.
I recommend using Chrome's JavaScript Console -- it outputs application cache events as they are happening, including errors.

how to show open/save dialog when linking to pdf files

I'm trying to link a pdf document from a static html file.
What I'm using is:
My pdf File
the open/save dialog comes up in firefox but not in IE7 or IE8.
I believe I have to change the MIME type but I don't know where to change it...
Since it works in Firefox I assume the file is actually there and accessible. In that case it depends on the browser settings how the download is handled. It might be that the download happens in the background because you setup that it should automatically download everything into a predefined folder (e.g. My Downloads/).
Check the IE settings to see where it puts downloads and check the folder to see if downloaded the file.