This works on Firefox but not on IE
window.open('/documents/some%20file.doc');
On IE it would open a new tab and immediately closes it. No save dialog.
Is there any way to let user download a file on IE using JavaScript if we have the file URL?
(The file URL is dynamic so it cannot be an <a href=''> tag)
Thanks in advance.
document.location.href = '/documents/some%20file.doc';
window.open("/documents/some%20file.doc","_self","fullscreen=no,toolbar=yes,width=800,height=600,menubar=yes,status=no,scroll=yes");
Related
Trouble opening an encoded URL with the javascript method window.open() using Internet Explorer. I have a Url: 'http://test.aspx?someparam=somevalue¶_new=somevalue'. When opening the URL the new IE tab has replaced the ¶_new with a paragraph character instead of being the ¶_new parameter (http://test.aspx/?someparam=somevalue¶_new=somevalue). This works fine using Chrome. Any help would be appreciated.
Please use window.open('http://test.aspx?someparam=somevalu¶_new=somevalue')
Change & to &
Ref link
I am developing a website which allows users to download a PDF version of a page. The current solution is to render the generated HTML to a PDF on the server, which returns the Base64-encoded PDF as a result. A Blob is created from this data, followed by an ObjectURL as follows: -
const blob = new Blob([B64A.decode(pdfdata)], {type: 'application/pdf'});
dataURL = (window.URL || window.webkitURL).createObjectURL(blob);
The dataURL (which is in the form "blob:http://www.example.com/abcd1234-abcd-abcd-abcd-abcd1234efa") is then assigned to the href attribute of an anchor tag. The target attribute is also set to "_blank" so that the generated PDF is opened in a new tab.
This worked absolutely fine up until around a week ago. In Firefox, everything still works, however in Chrome there is a problem. When clicking the link, a tab quickly opens and then immediately closes. Removing the target attribute causes everything to work properly, although the PDF is loaded into the current tab which is not what I want. Nothing is logged to the console, so I am not getting any clues from there.
Does anyone have any ideas as to why this is happening? As this has only just started happening I am assuming it's an issue with the latest version of Chrome (I am running 57.0.2987.98 (64-bit) on Linux, although a colleague also has the same issue with Chrome on Windows 10).
EDIT:
I just created a CodePen example to demonstrate this: https://codepen.io/anon/pen/OpOGbE
Click the button and two links should be generated. The first should open normally in the same page. The second should open in a new tab, but does not in Chrome (for me it displays the same behaviour as mentioned above).
While running this test I just noticed that in an incognito window the issue seems not to exist, and the new tab opens correctly...
It seem to be a temporary bug in Chrome. The code works with current Canary (beta) version of Chrome (v.59.0.3044.1) as of this writing.
As a temporary workaround you could try using the original Base-64 data and just prepend a data-uri header to it, then use this as source for href:
const dataURL = "data:application/pdf;base64," + pdfdata;
Using Chrome or Firefox I can easily do something like this in my HTML:
<a href="http://urlofmyblob.com/blobid"/a>
This immediately starts a download when the anchor linked is clicked in most browsers. However, in safari this only opens a new tab with the contents of my blob in text form. Does safari support downloading blobs from a remote URL? Also, is there a way I can do this using the href property in an anchor link?
The Following javascript code are used in my application to open the PDF file in new window, from the parent page.
onclick="window.open("myurl.pdf","Terms_and_Conditions","height=800,width=1000,dependent=yes,menubar=yes,scrollbars=yes,resizable=yes");"
I have tested in 5.1.4 version of Safari browser. It shows a blank black screen. Then,If i click/focus the window, the PDF content was loaded.
Please guide me to resolve. Thanks in advance.
Could you use an href with target="_blank" instead of javascript to do this? That way it would work even if the user has JS disabled.
I am looking for to fetch current tab (loaded or blank ) URL of Firefox browser.
How to acheive this ? using currentURI property in javascript.
Thanks a lot,
-Pravin
Is your code running inside an addon? You could use:
gBrowser.currentURI.spec