Rectangle 27 165

These files will still open in your browser and that is good

You need to use the file:/// protocol (yes, that's three slashes) if you want to link to local files.

<a href="file:///C:\Programs\sort.mw">Link 1</a>
<a href="file:///C:\Videos\lecture.mp4">Link 2</a>

These will never open the file in your local applications automatically. That's for security reasons, and I'll get to that in the last section. If it opens, it will only ever open in the browser. If it your browser can display the file, it will. If it can't, it will probably ask you if you want to download it.

Some browsers, like modern versions of Chrome, will even refuse to cross from the http protocol to the file protocol, so you'd better make sure you open this locally using the file protocol if you want to do this stuff at all.

The first part of a URL is the protocol. A protocol is a few letters, then a colon and two slashes. HTTP:// and FTP:// are valid protocols; C:/ isn't and I'm pretty sure it doesn't even properly resemble one.

C:/ also isn't a valid web address. The browser could assume it's meant to be http://c/ with a blank port specified, but that's going to fail.

Your browser may not assume it's referring to a local file. It has little reason to make that assumption, because public sites usually don't attempt to link to peoples' local files.

So if you want to access local files: tell it to use the file protocol.

Because it's part of the File URI scheme. You have the option of specifying a host after the first two slashes. If you skip specifying a host, it will just assume you're referring to a file on your own PC. In other words: file:///C:/etc is a shortcut for file://localhost/C:/etc.

Your browser will respond to these files the same way they'd respond to the same file anywhere on the internet. These files will not open in your default file handler (e.g. MS Word or VLC Media Player), and you will not be able to do anything like ask File Explorer to open the file's location.

Sites in your browser cannot interact with your operating system very well. If a good site could tell lecture.mp4 to open in VLC.exe, a malicious site could tell it to open virus.bat in CMD.exe. Or it could just tell your PC to run a few Uninstall.exe files, or to open File explorer a million times.

This may not be convenient for you, but HTML and browser security weren't really designed for what you're doing. If you want to be able to open lecture.mp4 in VLC.exe, consider writing a desktop application instead.

Thanks Jonathan. Do you know if there's a way to "show file in folder" as an alternative?

@Brian Your browser can't interact with your OS in that way, and you should be extremely glad it cannot.

Seems like Chrome won't download local files using the file:/// protocol anyway (giving you a Not allowed to load local resource error)

I want to give a link like this "file:///..\..\sort.mw" so that it goes back two folders and gets the file there. Because we are using the word file in dropbox. So is there any solution.

It might also worth mentioning you can not link from a website (e.g. local dev server) to a local file. forums.mozillazine.org/viewtopic.php?f=9&t=1730

html - How can I create a link to a local file on a locally-run web pa...

html anchor local-files
Rectangle 27 7

Also you should know that your logs grow very fast, and it's not a good idea to show whole log in browser. You can just open last 100-200 rows. Related topic: Reading the last n lines of a file in Ruby?

Also you can try this solution: http://newrelic.com/. It is more complex and little oftopic, but quite useful.

It's so simple when someone else gives you the solution :) Thank you, sir!

logging - Is there any way to display Rails' log files in the browser?...

ruby-on-rails logging
Rectangle 27 9

There is a good chance another site will also be using the same js files from Google's servers, so the file will already be cached by your browser and it won't need to download it again for your site.

Check out this article for some of the other benefits as well.

+1 If everyone took jquery from google, it would always be cached whatever site you went to!

I don't know about you guys and girls, but I'm going to go change all my sites right now.

Why is it important to load a JS framework from Google's AJAX Librarie...

api javascript-framework
Rectangle 27 54

The reason all these goroutines are reading is keep-alive. When a browser sends a keep-alive header, the server keeps the connection open to accept more requests. This is a good thing when the client is requesting many small files and the TCP connection is significant overhead. A read timeout would ensure that no connection was kept alive more than a certain time between requests. This would close keep alive connections but also prevent someone from uploading for longer than the timeout. Unfortunately, there is no keep-alive specific timeout option yet.

By default, there is no timeout. You can set a timeout in the Server struct http://golang.org/pkg/net/http/#Server

srv := &http.Server{
    Handler: http.FileServer(http.Dir(config.htdocs_path)),
    ReadTimeout: 30*time.Second,
}
srv.ListenAndServe()

Thanks! I'll give that a try for our update this week. :-)

Could you mark it as answered? Thanks

Sorry, I didn't know how to mark it as correct. Had to figure it out.

what is the diff between a ReadTimeout and a TimeoutHandler? They do the same thing, no? golang.org/pkg/net/http/#TimeoutHandler

go - Golang: http server leaving open goroutines - Stack Overflow

http go
Rectangle 27 33

Just a thought but what if you worked this problem from the opposite direction? Rather than determining which browsers are mobile why not determine which browsers are not? Then code your site to default to the mobile version and redirect to the standard version. There are two basic possibilities when looking at a mobile browser. Either it has javascript support or it doesn't. So if the browser does not have javascript support it will default to the mobile version. If it does have JavaScript support, check the screen size. Anything below a certain size will likely also be a mobile browser. Anything larger will get redirected to your standard layout. Then all you need to do is determine if the user with JavaScript disabled is mobile or not. According to the W3C the number of users with JavaScript disabled was about 5% and of those users most have turned it off which implies that they actually know what they are doing with a browser. Are they a large part of your audience? If not then don't worry about them. If so, whats the worst case scenario? You have those users browsing the mobile version of your site, and that's a good thing.

Just a thought but what if you worked this problem from the opposite direction? Rather than determining which browsers are mobile why not determine which browsers are not? Then code your site to default to the mobile version and redirect to the standard version. There are two basic possibilities when looking at a mobile browser. Either it has javascript support or it doesn't. So if the browser does not have javascript support it will default to the mobile version. If it does have JavaScript support, check the screen size. Anything below a certain size will likely also be a mobile browser. Anything larger will get redirected to your standard layout. Then all you need to do is determine if the user with JavaScript disabled is mobile or not. According to the W3C the number of users with JavaScript disabled was about 5% and of those users most have turned it off which implies that they actually know what they are doing with a browser. Are they a large part of your audience? If not then don't worry about them. If so, whats the worst case scenario? You have those users browsing the mobile version of your site, and that's a good thing.

This is a very good idea, I think it's an elegant solution.

This is a very good idea, I think it's an elegant solution.

+1 this sounds like a pretty sweet idea, but would this affect search engine crawlers?

+1 this sounds like a pretty sweet idea, but would this affect search engine crawlers?

This is a misguided idea. Browser extensions that disable javascript are very popular on desktop browsers, so assuming that no javascript means mobile is just plain wrong. Window/viewport/screen resolution has nothing to do with a browser's size, and assuming that low resolution indicates handheld size will make your web app ugly and frustrating to many users. (For example: desktop browsers in non-full-screen windows, large tablets.)

html - Auto detect mobile browser (via user-agent?) - Stack Overflow

html windows-mobile browser user-agent
Rectangle 27 33

Just a thought but what if you worked this problem from the opposite direction? Rather than determining which browsers are mobile why not determine which browsers are not? Then code your site to default to the mobile version and redirect to the standard version. There are two basic possibilities when looking at a mobile browser. Either it has javascript support or it doesn't. So if the browser does not have javascript support it will default to the mobile version. If it does have JavaScript support, check the screen size. Anything below a certain size will likely also be a mobile browser. Anything larger will get redirected to your standard layout. Then all you need to do is determine if the user with JavaScript disabled is mobile or not. According to the W3C the number of users with JavaScript disabled was about 5% and of those users most have turned it off which implies that they actually know what they are doing with a browser. Are they a large part of your audience? If not then don't worry about them. If so, whats the worst case scenario? You have those users browsing the mobile version of your site, and that's a good thing.

This is a very good idea, I think it's an elegant solution.

+1 this sounds like a pretty sweet idea, but would this affect search engine crawlers?

This is a misguided idea. Browser extensions that disable javascript are very popular on desktop browsers, so assuming that no javascript means mobile is just plain wrong. Window/viewport/screen resolution has nothing to do with a browser's size, and assuming that low resolution indicates handheld size will make your web app ugly and frustrating to many users. (For example: desktop browsers in non-full-screen windows, large tablets.)

html - Auto detect mobile browser (via user-agent?) - Stack Overflow

html windows-mobile browser user-agent
Rectangle 27 33

Just a thought but what if you worked this problem from the opposite direction? Rather than determining which browsers are mobile why not determine which browsers are not? Then code your site to default to the mobile version and redirect to the standard version. There are two basic possibilities when looking at a mobile browser. Either it has javascript support or it doesn't. So if the browser does not have javascript support it will default to the mobile version. If it does have JavaScript support, check the screen size. Anything below a certain size will likely also be a mobile browser. Anything larger will get redirected to your standard layout. Then all you need to do is determine if the user with JavaScript disabled is mobile or not. According to the W3C the number of users with JavaScript disabled was about 5% and of those users most have turned it off which implies that they actually know what they are doing with a browser. Are they a large part of your audience? If not then don't worry about them. If so, whats the worst case scenario? You have those users browsing the mobile version of your site, and that's a good thing.

This is a very good idea, I think it's an elegant solution.

+1 this sounds like a pretty sweet idea, but would this affect search engine crawlers?

This is a misguided idea. Browser extensions that disable javascript are very popular on desktop browsers, so assuming that no javascript means mobile is just plain wrong. Window/viewport/screen resolution has nothing to do with a browser's size, and assuming that low resolution indicates handheld size will make your web app ugly and frustrating to many users. (For example: desktop browsers in non-full-screen windows, large tablets.)

html - Auto detect mobile browser (via user-agent?) - Stack Overflow

html windows-mobile browser user-agent
Rectangle 27 26

The way this works in all browsers are that each domain gets a limited amount of connections and the limits are global for your whole application. That means if you have one connection open for realtime communication you have one less for loading images, css and other pages. On top of that you don't get new connections for new tabs or windows, all of them needs to share the same amount of connections. This is very frustrating but there are good reasons for limiting the connections. A few years back, this limit was 2 in all browsers (based on the rules in (http://www.ietf.org/rfc/rfc2616.txt) HTTP1.1 spec) but now most browsers use 4-10 connections in general. Mobile browsers on the other hand still needs to limit the amount of connections for battery saving purposes.

  • Use more host names. By assigning ex. www1.domain.com, www2.domain.com you get new connections for each host name. This trick works in all browsers. Don't forget to change the cookie domain to include the whole domain (domain.com, not www.domain.com)
  • Use web sockets. Web sockets are not limited by these restrictions and more importantly they are not competing with the rest of your websites content.

Reuse the same connection when you open new tabs/windows. If you have gathered all realtime communication logic to an object call Hub you can recall that object on all opened windows like this:

window.hub = window.opener ? window.opener.hub || new Hub()
  • or use flash - not quite the best advice these days but it might still be an option if websockets aren't an option.
  • Remember to add a few seconds of time between each SSE request to let queued requests to be cleared before starting a new one. Also add a little more waiting time for each second the user is inactive, that way you can concentrate your server resources on those users that are active. Also add a random number of delay to avoid the Thundering Herd Problem

Another thing to remember when using a multithreaded and blocking language such as Java or C# you risk using resources in your long polling request that are needed for the rest of your application. For example in C# each request locks the Session object which means that the whole application is unresponsive during the time a SSE request is active.

NodeJs is great for these things for many reasons as you have already figured out and if you were using NodeJS you would have used socket.io or engine.io that takes care of all these problems for you by using websockets, flashsockets and XHR-polling and also because it is non blocking and single threaded which means it will consume very little resources on the server when it is waiting for things to send. A C# application consumes one thread per waiting request which takes at least 2MB of memory just for the thread.

Great answer! Do you know why Firefox was refusing to open any other domain whatsoever?

Thanks ; unfortunately the window.opener trick will only work for child windows that I create from my app ; not for any tab that the user opens herself. As soon as the user opens too many tabs, I'm screwed... Do you know if there is a way to check that we're about to exhaust all open connections ?

Try using (window.parent || window.opener) which will take care of both scenarios. Also look at the postMessage method for sending cross tab messages. I don't think there are any way of seeing amount of connections but you should rather use the timeout property to be able to react to scenarios where the long-polling request is stalling other requests. xhr = new XMLHttpRequest(); xhr.timeout = 5000; xhr.ontimeout=timeoutFired;

Sunyatasattva - yes - ALL connections are included - even new pages. Which means if you have four open tabs, each with its own long-polling connection you have used all your connections and since the long-polling requests were going to the same domain the global limit for that domain was exhausted. Best way to prevent this is to use separate domain for the long-polling connection (or reuse connections), that means the ordinary page-load will not be affected - just the realtime connection.

Please mark this as the answer if you are satisfied?

javascript - Server sent events and browser limits - Stack Overflow

javascript google-chrome cross-browser opera server-sent-events
Rectangle 27 2

Is probably more related to the type of files that you browser is configured to open.

If the browser does not know how to open certain type of files it will prompt you to download it

Another thing is that you have specified octect-stream for a TXT file

Content-Type: application/octet-stream
Content-Disposition: attachment;filename=\"My Text File.txt\"

Which actually forces the Browser to download the content as mentioned here

File types are the same. We have a legacy ColdFusion application that does this same thing and the file is automatically downloaded.

Actually on second thought it is a different file type. The CF program is getting the actual document, where this web services is returning a proprietary file type that opens with a proprietary program and gets the actual document, so this could be it.

.NET Web Service - download file and force browser to open it - Stack ...

.net web-services asmx
Rectangle 27 267

This error is happening because you are just opening html documents directly from the browser. To fix this you will need to serve your code from a webserver and access it on localhost. If you have Apache setup, use it to serve your files. Some IDE's have built in web servers, like JetBrains IDE's, Eclipse...

npm install http-server -g
http-server C:\location\to\app

The http-server is the simplest way I've seen of hosting locally. Note: If you don't have npm on windows, just install node.js and it'll become available in cmd.

And if it's happened in webview in android, what should i do!?

Out of curiosity, why isn't it possible to just open the files in the web browser ?

@reddy Plain and simple: It is a security issue for the browser to access the filesystem directly on your computer.

javascript - AngularJS Error: Cross origin requests are only supported...

javascript html angularjs xmlhttprequest
Rectangle 27 59

From a "sniff the network packet" point of view a GET request is safe, as the browser will first establish the secure connection and then send the request containing the GET parameters. But GET url's will be stored in the users browser history / autocomplete, which is not a good place to store e.g. password data in. Of course this only applies if you take the broader "Webservice" definition that might access the service from a browser, if you access it only from your custom application this should not be a problem.

So using post at least for password dialogs should be preferred. Also as pointed out in the link littlegeek posted a GET URL is more likely to be written to your server logs.

ssl - Is an HTTPS query string secure? - Stack Overflow

ssl https query-string
Rectangle 27 59

From a "sniff the network packet" point of view a GET request is safe, as the browser will first establish the secure connection and then send the request containing the GET parameters. But GET url's will be stored in the users browser history / autocomplete, which is not a good place to store e.g. password data in. Of course this only applies if you take the broader "Webservice" definition that might access the service from a browser, if you access it only from your custom application this should not be a problem.

So using post at least for password dialogs should be preferred. Also as pointed out in the link littlegeek posted a GET URL is more likely to be written to your server logs.

ssl - Is an HTTPS query string secure? - Stack Overflow

ssl https query-string
Rectangle 27 28

status is 0 when your html file containing the script is opened in the browser via the file protocol.Make sure to place the files in your server(apache or tomcat whatever) and then open it via http protocol in the browser.(ie http://localhost/myfile.html) This is the solution.

Why is this being downvoted? It is actually true! XHR requests from file:// URLs of files also on file:// URLs actually have status == 0 on success (tested on FF 24.0.5).

thanx from me as well. this saved my day

I'm also getting status == 0 on success on Safari Version 6.1.6.

I'm having status=0 (but status 200 on network) using Load temporary add-on on firefox

javascript - XMLHttpRequest status 0 (responseText is empty) - Stack O...

javascript ajax xmlhttprequest
Rectangle 27 1

The behaviour should depend on how the browser is set up to handle various MIME types. In this case the MIME type is application/pdf. If you want to force the browser to download the file you can try forcing a different MIME type on the PDF files. I recommend against this as it should be the users choice what will happen when they open a PDF file.

javascript - (HTML) Download a PDF file instead of opening them in bro...

javascript html
Rectangle 27 1

It is possible to let users download data as CSV files from the browser, which will open in Excel for most users.

You can also copy delimited text to the user's clipboard using Clipboard.SetText which the user can then paste into a running instance of Excel.

Another option would be to use a server-side service to generate an Excel document and have the Silverlight application show a hyperlink to the document.

Invoking out of browser app from in-browser app in silverlight - Stack...

silverlight silverlight-5.0
Rectangle 27 4

the idea IS NOT trust in the Browser..the idea is perform this validations on SERVER SIDE but, what a usefull thing if prior to send a 20MB file to the browser and next get rejected because a rule in the server...so, it is a good idea to "pre-check" if this file "is a candidate" to be uploaded, the final validation will be performed in the server.

jQuery or JavaScript: get MIME type of client file - Stack Overflow

javascript jquery mime-types
Rectangle 27 4

the idea IS NOT trust in the Browser..the idea is perform this validations on SERVER SIDE but, what a usefull thing if prior to send a 20MB file to the browser and next get rejected because a rule in the server...so, it is a good idea to "pre-check" if this file "is a candidate" to be uploaded, the final validation will be performed in the server.

jQuery or JavaScript: get MIME type of client file - Stack Overflow

javascript jquery mime-types
Rectangle 27 1

Think about WebClient as the replacement of your browser. Creating a new WebClient is like starting a new browser. If you like to do something equal to open a new tab in your browser, you can use WebClient#openWindow(..). And from the memory point of view it is a good idea to close the window if you are done.

If you are looking for performance, why you re-parse the whole page Jsoup. HtmlUnit retrieves the page, parses the page, creates the whole DOM and runs the javascript on top of this dom before your are getting back the page from your getPage call. Then you are using HtmlUnit to serialize the Dom tree back to Html and use Jsoup to parse the page again. HtmlUnit offers many ways to search for elements on a page. I'm suggesting to use this API directly on the page you got.

Thanks for your anwer, expecially for suggestion about doing everything with HtmlUnit. I will look to API deeply. Regarding WebClient. I was exactly thinking to it as a broswer and that's why it comes in mind the "second way". If I'm running a browser and I have finished to look at a page and I need to go in a new one, I just change address, instead of closing the browser opening it again or going in a new tab.

java - HtmlUnit: opening new page with the same WebClient - Stack Over...

java jsoup webclient htmlunit
Rectangle 27 38

Using an iframe to "render" a PDF will not work on all browsers; it depends on how the browser handles PDF files. Some browsers (such as Firefox and Chrome) have a built-in PDF rendered which allows them to display the PDF inline where as some older browsers (perhaps older versions of IE attempt to download the file instead).

Instead, I recommend checking out PDFObject which is a Javascript library to embed PDFs in HTML files. It handles browser compatibility pretty well and will most likely work on IE8.

div
<div id="pdfRenderer"></div>

Then, you can have Javascript code to embed a PDF in that div:

var pdf = new PDFObject({
  url: "https://something.com/HTC_One_XL_User_Guide.pdf",
  id: "pdfRendered",
  pdfOpenParams: {
    view: "FitH"
  }
}).embed("pdfRenderer");

This produced nothing different than just loading the pdf in an iframe...

That's the point. But it's loading the PDF into an object instead of an iframe. See pdfobject.com/markup/index.php

What if you don't want the src path of your pdf file exposed in the objects data tag?

well wouldn't the src path be shown in an iFrame to? ^

Does not work with ie8. Only ie9+.

javascript - How to open a PDF file in an