A new open window opens, but closes immediately

I am trying to upload a file from FTP using javascript, for which I created the following section:

Can I upload a file from FTP using Javascript?

From there I learned that I can use window.open('ftp://xyz.org/file.zip'); to download the file. It opens a new browser window, but the window closes immediately.

How can I make him stay open?

Actually, I do all this in a Silverlight application:

Here is the code:

 HtmlPage.Window.Eval("window.open('" + url+ "', 'Download', 'height=500,width=800,top=10,left=10');"); 

I also tried this,

 string targetFeatures = "height=500,width=800,top=10,left=10"; HtmlPage.Window.Navigate(new Uri(url), "_blank", targetFeatures); 

But both results coincide: he opens a window and closes it immediately. I see it only for a split second!

+6
javascript c # silverlight
source share
7 answers

I know that this does not answer your question, and I am sure that you all know this. I answer more, because I do not see this moment often arise. :)

Silverlight has very limited customer interaction support. Javascript is a gasket that, in my opinion, is being abused to try to get around everything that was against Silverlight. It would be very easy for Microsoft to enable FTP support in Silverlight, but it was ruled out for some reason.

However, Silverlight has excellent support for interacting with webservice. Therefore, the recommended way to retrieve the file would be to call a web service that will do the FTP transfer for you, and then send the content to the Silverlight application through the web service. Perhaps even processing it on the webservice side for any business logic, etc.

As I said, I suspect that your requirement is not to use a web service (most likely, in order to bring the cost of bandwidth per user). But it would be interesting to learn more about your business problem instead of your technical problem for your chosen solution.

+3
source share

It closes because it starts the file download. You can open two windows - one for the message and one for downloading the file, but I want it to know that it is loading ...

+2
source share

If I were you, I would open a page in which there are any visual / user materials that you would like to show to the user, and either have a META tag that is redirected to the download URL or has a javascript ad unit for fire off download . Thus, your window will remain open, but the download will still start automatically.

+2
source share

to keep it open.

 var test = window.open(); test.location = 'ftp://openbsd.org.ar/pub/OpenBSD/2.0/arc/kernels/bsd.ecoff'; 

and not open any window use

 window.location = 'ftp://openbsd.org.ar/pub/OpenBSD/2.0/arc/kernels/bsd.ecoff'; 

or make a normal link

+1
source share

Remember that the browser is not designed to "display" (visually in any case) the FTP protocol, and not all browsers will support it. If you want the user to be able to download something, consider using the normal http: // protocol and opening a window, as others have suggested.

If you really need a download that will be hosted via FTP, consider that your server uses (and caches) the file and returns it to the user via http

0
source share

The browser does not analyze anything, so it closes. If you want to open the page, you will have something dirty. Like creating an html (or php) page and serving the content that you want the user to see, then with a hidden i-frame that will call the FTP content.

Thus, your user will see the content that you want to see, and the file is uploaded.

0
source share

I had the same problem, Silverlight opening a new window for downloading a file would instantly launch a blank window and disappear again without downloading the file.

This seems to have happened in IE 8 (not 9 or higher) and can be fixed by going to Tools-> Internet Options-> Security, then select User Level ... (for any zone your site will be in) and to Downloads-> Automatically prompt to download files and make sure it is turned on (I also have the option of downloading files below). This automatic indication of file upload settings is apparently missing in IE 9 +.

Another workaround is not opening in a new window, if the destination URL immediately loads the file, it will not change the current window, so there is no difference in UX:

 HtmlPage.Window.Navigate(new Uri("\download.ashx?fileid=12345")); 
0
source share

All Articles