I'm having a problem using the RFC 2397 data url scheme with IE versions 6-9. My sample code below works without problem when using current versions of Safari, FF, Opera and Chrome.
data:text/html;base64,PG1ldGEgaHR0cC1lcXVpdj0icmVmcmVzaCIgY29udGVudD0iMDt1cmw9aHR0cDovL2dvb2dsZS5jb20vIj4g
or
data:text/html,%3Cmeta%20http-equiv%3D%22refresh%22%20content%3D%220%3Burl%3Dhttp%3A//google.com/%22%3E%20
If the above code is pasted in almost any browser excluding IE it will navigate to google.com, when attempting with IE it fails with the following error.
The webpage cannot be displayed
Most likely cause:
- Some content or files on this webpage require a program that you don't have installed.
What you can try:
Search online for a program you can use to view this web content.
Retype the address.
When inspecting the page source of the IE error page generated there is a link that makes reference to File Associations and protocols.
Protocol Type:
Description: UnKnown
Windows does not recognize this Protocol.
I realize that using the data: protocol is probably not the most straight forward or in most cases the best option, but I must use it for this particular project.
I have searched all over for a solution and tried many examples with IE hoping it was my syntax but have yet found a solution.
Two alternative solutions are explained here: http://sparecycles.wordpress.com/2012/03/08/inject-content-into-a-new-iframe/
The main difference I can tell is that the iframe has the same origin as the original page, which might not be desired (I am unsure of security implications e.g. what the referer or cookies might be for loaded resources).
An example of using the javascript: scheme technique is here: http://jsbin.com/uhenuz/4 (If used with https would need extra googling and good testing to check that mixed https/http warning can never come up.)
According to Franco's answer here: CSV file export For IE
Just create a Blob object with it
And it works for me!
Data URIs cannot be used for navigation, for scripting, or to populate frame or iframe elements in IE.
According to http://msdn.microsoft.com/en-us/library/cc848897%28v=vs.85%29.aspx:
I got here while I was looking for a way to feature detect for data uri support of files (PDFs in my case). The Modernizr approach of checking for image support was not good enough since Internet Explorer 11 and Edge 25 do support that but don't support file types like application/pdf. Snekse's approach of checking for the download attribute worked on IE but not Edge. Eventually, I wrote my own feature detection script using an AJAX call to attempt to open a data URI and checking for errors. This is the script I used (tested in IE 11, Edge 25, Firefox 46, and Chrome 49):
Update
I realized that any code that is testing for data URI is iframe support is also testing for supporting opening a data URI in a new window. Thus, the solution mentioned in this SO answer and linked to in Snekse's answer update is technically superior and I would recommend using it instead of the above code.
Internet Explorer does support Data URIs (resource is a bit out of date). It has some security considerations though which prevent it from allowing malicious attempts to redirect users, or otherwise allow hackers to engage in phishing without requiring 3rd party scripts or hosted resources.
This means you can use it with JavaScript:
Cascading Style Sheets (with, or without base64 encoding):
Or even images:
You cannot, however, use these with
window.open
oriframe
, as these would allow some very dangerous things, including Phishing with Data URIs:This last example could very well have been a full-on replica of the PayPal login screen. Instead, it's just an HTML button with an event-handler bound and listening for clicks. Similar hackery could come by way of
window.open
:So Internet Explorer 10 supports this feature, but it protects the end-user from those who would use it maliciously. I'm sure Microsoft will gladly lift this restriction when and if they determine a better way to protect their user-base.
Until things change, you need to find another way to include your FLV files. On a side-note, you may not want to share actual data like this from your application on Stack Overflow.
For me, finding
document.execCommand
was a life saver. It uses theiFrame
like some of the other examples, but theexecCommand
makes theSave As
functionality consistent.Here's an example
We do this for IE and for all other browsers we use the standard Data URI link. You can see the full gist for more details. A hat tip to Andrew Blondeau for the direction.
UPDATE
A better way to determine if the browser support a Data URI
supportsDataUri = 'download' in document.createElement('a');
It also seems like IE still runs into issues. For IE10+ you might need to use
msSaveOrOpenBlob
and for IE8/9 you still need to do theexecCommand
in aniFrame
.UPDATE 2
There is a Modernizr issue for detecting data uri scheme. It references another SO answer. Be sure to also check those out.