Is it possible not to allow iframe to show file download popup? - javascript

I have a code like:
<iframe src="http://www.upnp.org/download/UPNP_understandingUPNP.doc"></iframe>
When this code is rendered, browser file download prompt is shown to user. I'd want to prohibit iframe from showing this download popup.
Is it possible?
I'd want it as iframe's url is controlled by users, not site owner.

No.
The server hosting the URL can decide if it wants to mark it as an attachment (suggesting that the browser to save it) or inline (suggesting that the browser should open it; using a plugin if one is available).
The browser decides how to handle it.
The page linking to it (even if it does so via an iframe) has no control over any of the above.

To avoid the download popup, you could use ajax instead of an iframe to load the url.

Related

How to stop browser open a pdf file?

I am building a website and there is an embed iframe on the page. I found that when users drop a pdf file over the iframe. The browser will close my website and load the pdf. How can I stop browser rendering the pdf file? I know the drop event I can use but this case happens in the iframe. Is there a way for me to handle drop over iframe? My iframe is loading a url which is not the same origin as the parent window.
I don't have control on the iframe I am embedded. What I want is if the iframe doesn't handle drop event then I disable the drop otherwise let iframe to handle it.
This isn't specific to an iframe, it just is what browsers do when you drag a pdf onto them - or most other files they can open, as far as I know. I wouldn't worry about it. If it's fine for every other site, it's probably fine on yours. If a user has complained, just explain it's the browser and there is nothing you can do.
People might try and find hacky ways to disable it, but my recommendation is not to.

Download a pdf (not open in tab) in Javascript

I have a landing page on which there is a form which is filled by user and then it goes to a thank you page (which is another page). On thank you page I simply want to prompt the user for saving a pdf as the thank you page loads. Please note I want the file to be saved/downloaded and not opened on the same tab or another tab in the browser. I have tried multiple solutions but they all seem to open the pdf in the browser itself and not download it. Some of the methods I have tried are meta tag download, page redirect download, iframe download but they all open the pdf in browser itself and not download it. I just want a simple solution for downloading the file and not opening it in the browser. Also the pdf should download automatically without clicking any link or button.
The document.ready event of the thank you page should trigger a local script that runs a server script to download the PDF. Be sure to set the headers as described above. If you try to link directly to the PDF, it'll try to load in the browser.
Alternatively, you could create the PDF in a directory that is already set to only download files by setting the .htaccess file for that directory.

Submit form in an iframe to a cross domain page

I wrote a chrome extension which injects a toolbar on top of sites (say amazon.com) as an iframe at the top.
When the user click on the action button on the toolbar (inside iframe), it's basically a form submit action, with action pointing to my full site (on another domain).
It's working, however only inside the iframe. I'd like the whole page to redirect to my site, rather than the iframe.
Is there anyway to do that in extension?
If you are using an iframe :
Same Origin Policy prevents you from doing this.
Unless you can hack/XSS the other site's files to inject the JS, you will have a hard time.
Now if you legitimately need to communicate with the other page, and you either have control of the other page or can setup it to communicate with your server, you can use window.postMessage, JSONP or even Ajax with CORS (latter 2 will be harder to pass dynamic content though). But I believe it is not the case.
else :
you can directly inject the js script in to the page itself by that you can handle all operations in the main page same as running something on chrome console.

Opening a popup after receving message via postMessage

There is an iframe on my site which is hosted on another domain. It can communicate to the main site via window.postMessage. I do have a button on that iframe which calls a JS method on the main domain, which then triggers a new window.
It all seems good but since the user click event is generated on the iframe domain and window is created on the main domain, browser thinks that this is an automated popup, and blocks.
Is there anything I can do to prevent browser from blocking the window?
since that is browser based you cannot overwrite browser settings. But you can use javascript "modals" which are very useful since they are not pop-ups but they don't have the functionality of an pop-up

Close browser popup page after downloading file

When user clicks on a hyperlink, i am opening a popup window which downloads a file. Post download, it shows open/save dialog box. I want to close the popup window once the download is done (when user is prompted for saving the file).
I have tried window.close method, but it doesnt work as the context is not the popup window but the open/save dialog box.
I think you can not control it programatically. This is browser-specific thing where some browsers allow you to tick on a check box to close the window and so on.
you can do one thing:
after the "file writing code in your servlet or struts action use"
Step 1: call "response.flushBuffer();"
Step 2: call response.sendRedirect("close.htm")
where close.htm is :
<html>
<script>
window.close();
</script>
</html>
Only problem is identifying if the download is complete. I don't think there is a possible way of doing that. Anyway is there any use of keeping the pop-up open untill the download is complete. You can simply close the pop-up once the download is initiated. Using below JavaScript, can't you?
pop_up= window.open("", "PopUpName");
pop_up.document.write('POPUP TEXT');
pop_up.close();
Browsers have a habit of deciding for themselves whether to try to download a file or open it inside the browser window, depending on the browser used, plug-ins and server settings. It sounds like you might be opening the link in a new window, as if the browser was going to open the file rather than download it, and then the browser has opted for the download. This leaves the user with a downloaded file and a blank window that you have no control over.
To force it to download, you should be able to set the Content-Type header for the target of the link to application/force-download. How you do this will depend on your setup, and whether the file is downloaded directly (in which case it will be a server setting) or via PHP or .Net (in which case it's easy to programmatically set the header). Also make sure that the hyperlink doesn't have a target="_blank" attribute that opens the link in a new window.
It's Browser functionality, You can change browser setting for that. You shouldn't go for programming . By default If you will download file in firefox it ask for saving, but in crome It's doesn't ask.
You need to change setting of your browser.

Categories

Resources