We have a pretty standard file selector on our web page, defined like this:
<input type="file" multiple="" accept=".csv,.json,.zip,.jpg,.jpeg,.bmp,.png,.gif,image/*">
This works fine for selecting a local file, but we found that if the user pastes a URL in to the "file name" field, the browser (chrome and firefox tested) will download that URL to a temporary file and set the result of the file chooser to that temporary file.
It looks like the name of that temporary file is based only on the URL given; that is, a URL like http://server/path/download?id=123 will result in a name of "download", while a URL like http://server/path/123.jpg will result in a name of "123.jpg", regardless of any headers defined on the response (e.g. content-disposition).
So my questions:
Is this behavior documented somewhere? I couldn't find it in MDN.
Can this feature be disabled to only allow selection from the local file system?
Is there a way to control the file name other than the URL?
As it turns out, I think this behavior is actually coming from the operating system (windows 10), not the browser dialog, as I can reproduce the same behavior using other applications. For example, in Eclipse I can paste URLs in the file open dialog, and they open in Eclipse with the same naming scheme. I also tried on a few other OS's and, as expected, the dialog is provided by the OS so in some cases didn't even have a way to input a URL.
Related
Inputs with autocomplete enabled are working properly when opening in mobile Safari but not when loaded in a WKWebview (iOS 11.3). Is this a known limitation?
https://developer.apple.com/documentation/security/password_autofill/enabling_password_autofill_on_an_html_input_element?language=objc
Try using the below format to get html autofilling your fields
<input id="user-text-field" type="email" autocomplete="username"/>
I know I'm late to the party, but I had a surprisingly hard time finding a solution to such an old problem, so I wanted to share since this is still high on the Google results.
The autofill that I wanted was for the WKWebView to autocomplete a saved username and password for easy login. However, this could present a security risk to the user, so you have to add the "Associated Domains" entitlement to the iOS app that tells it which domains/subdomains it can trust, and you have to add a JSON file to the web site server's wwwroot/.well-known directory to prove that you control the site you are displaying in the WKWebView. Once that is done, then the username/password is autosuggested the same way that it is in Safari.
Here is the Apple documentation: https://developer.apple.com/documentation/xcode/supporting-associated-domains
To summarize the steps I took, in XCode, I went to the "Signing and Capabilities" tab in my app target, clicked the "+ Capability" button, added Associated Domains, and put entries in the newly created list for all of my subdomains:
webcredentials:example.com
webcredentials:www.example.com
webcredentials:othersubdomain.example.com
And then on my web server, I added a file to the .well-known directory called "apple-app-site-association" (no extension) with the following contents:
{
"webcredentials": {
"apps": [ "ABCDE12345.com.example.myapp" ]
}
}
(where the format for the identifier is <Application Identifier Prefix>.<Bundle Identifier>). Then I browsed to https://www.example.com/.well-known/apple-app-site-association to make sure that the json was displayed in the browser.
Note: I use ASP.Net Core MVC, and the file WASN'T displayed in the browser since it doesn't use a recognized file extension. I found several methods for getting around that - I chose to add a file extension to the file and then use a rewrite rule in startup.cs so that Apple can find the file without supplying the extension in the request. You can find more on that at asp.net core - How to serve static file with no extension
I've created a file in HTML and would like to set a default browser to have this load from. Can this be done using HTML, or does javascript have to be added to do so?
You can do that locally as part of a shortcut. So right click in desktop> create new shortcut and you can put the path to the browser followed by the html path.
Try this in the target of the shortcut
"C:\Program Files\Internet Explorer\iexplore.exe" C:\Users\user\Desktop\1.html
There will be no other way to start a local program from HTML or JavaScript on the users computer.
To add to SANM2009's answer: you can't set the default browser via HTML or JavaScript, as this would be a huge security flaw that could be exploited to allow malicious code to be set to run when loading HTML files (with even further potential repercussions).
SANM2009's answer is the most direct way to accomplish what you want to do if you only need to do this on your local computer. If you need to distribute your solution then you could use a batch file or PowerShell file to open a specific browser.
To create a batch file, just open a text editor and enter the following (this will open Firefox in this case):
start "firefox.exe" "path to your html file goes here"
Save that as a file with a .bat extension, such as openmyhtml.bat, and then you can just double click that file to open your HTML file in Firefox.
To accomplish the same in PowerShell, open a text editor and enter the following:
Start-Process "firefox.exe" "path to your html file goes here"
Save that with a .ps1 extension, such as openmyhtml.ps1, and then you can double-click that.
Batch files are more universally supported, so that's probably your best bet, unless there's a specific reason you'd want to use PowerShell.
After further investigating the file, when opening the shortcut it showed the incorrect path to the file in the browser. I dropped the file in chrome directly to see the path is detected and set that in the target. It is now working. Thank you both
How do I find the filename of an website I am inspecting with Firebug? As example when I look on http://example.org/ I can view inspect the Element, I see the whole html structure but I didn`t find the filename. I am searching for index.html or something in that way. Maybe this is an analog question, but I am not sure, because he/she is working with php. LINK
I know there are some solutions with Dreamweaver or other tools but I am searching for an easy way to figure that out with Firebug or an free Browser Add-On. I Hope you have a solution for that.
The URL you entered is the one that usually returns the main HTML contents. Though on most pages nowadays the HTML is altered using JavaScript. Also, pages are very often dynamically generated on the server.
So, in most cases there is no static .html file.
For what it's worth, you can see all network requests and their responses within Firebug's Net panel.
Note that the URL path doesn't necessarily reflect a file path on the server's file system. It is depending on the server configuration, where a specific URL maps to in the file system. The simplest example is the index file that is automatically called when a domain is accessed. In the case of http://example.org the server automatically loads a file index.html in the file system, for example.
So, in order to get the file name on the file system, you need to either check the server configuration or the related access logs.
I'm working on a web page. In chrome, Is there a way to return original path of some file, rather than fake path. I need my page to read the local path which the user selects and that local user path will be sent to back end for some functionality.
Chrome always returns C:/fakepath/text.txt but I need actual path like C:/users/abc/text.txt (original path)
Is there a way to do that by changing some chrome settings ?
You can't, security feature. And because it's a security feature, there's no way around it. disclosing the path could give away personally identifiable information such as the users real name (common account name) or the location of other similar files.
If an image file name does not reflect its correct file type(e.g stored with .pdf extension), is it safe to use it in HTML? Will the browser decide the correct type of the image? Will mobile browsers be able to deduce correct file type?
I have tested it with google chrome, it is working, but Is it guaranteed to run on all reasonable browsers?
UPDATE: I can't rename them to correct extensions, since they will be uploaded by users and then shown again.
Will mobile browsers be able to deduce correct file type?
Browsers don't usually deduce file types (there are exceptions, notably in IE—resulting in text files discussing HTML being treated as HTML and IIS servers sending text/plain content-types for HTML documents without their owners noticing—but they shouldn't be the primary concern).
Instead, browsers determine the type of data by examining the HTTP Content-Type Response header. By default, most servers will set this based on the file extension of the file they are reading from the filesystem to serve to the client.
You can override this, but doing so is fiddly and could cause problems if people save a file before opening it from their local file system (because it will have the wrong extension and their OS will associate it with the wrong application).