开发者

New opened window opens but closes immediately

I'm trying to download file from FTP using javascript, for which I created the following topic:

Is it possible to download 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 browser new window, but the window closes immediately.

How I can I force it to stay open?

Actually I do all these in 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.Nav开发者_JAVA技巧igate(new Uri(url), "_blank", targetFeatures);

But both results in same : it opens a window, and closes it immediately. I see it just for fraction of second!


I know this doesn't answer your question, and I'm sure you know all of this. I'm answering more because I don't see this point brought up often. :)

Silverlight has very limited support for client interactions. Javascript is a shim that in my opinion gets overused to try and bypass things that Silverlight was architectured against. It would have been very easy for Microsoft to include FTP support in Silverlight but it was excluded for a reason.

However, Silverlight has great support for webservice interactions. So the recommended way of getting a file would be to call a webservice that would do the FTP transfer for you and then send the contents down to the Silverlight application via the webservice. Possibly even processing it on the webservice side for any business logic etc.

Like I said, I suspect your requirement is to not use a webservice (to pass the bandwith cost onto the user most likely). But it'd be interesting to know more about your business problem instead of your technical problem for the solution you've chosen.


It closes because it triggers file download. You can open two windows - one for message and one to download file, but I thiunk user will know it is downloading...


If I were you, I'd open up a page that has whatever visual/UI stuff you'd want to show the user, and either have a META tag that redirects to the download URL, or has a javascript blurb to fire off said download. That way, your window will stay open, but the download will still start automatically.


to keep it open use

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

and to not open any window use

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

or make a normal link


Remember that a browser is not meant to "display" (visually anyway) the FTP protocol, and not all browsers will suport it. If you want to allow the user to download something, consider using a normal http:// protocol, and opening a window normally as others have suggested.

If you really need the download to be hosted via FTP, consider your backend ingesting (and caching) the file and return it to the user via http


There is nothing to be parsed on the browser's side, hence it closes. If you want to have the page open, you'll have todo something dirty. Like creating a html (or php) page and serve the content you want the user to see, then with a hidden i-frame which will call the FTP contents.

This way your user will see the content you want them to see, and the file is being downloaded.


I had the exact same problem, Silverlight opening a new window for downloading a file would flash a blank window up briefly and it would disappear again without the file download occurring.

This seemed to happen in IE 8 (not 9 and up) and could be fixed by going into Tools->Internet Options->Security then click Custom level... (for whatever zone your site would be in) and go to Downloads->Automatic prompting for file downloads and make sure this is Enabled (I also have File download enabled below that). This Automatic prompting for file downloads setting seems to be absent from IE 9+.

Another workaround is to not open in a new window, if the target url immediately downloads a file it won't change the current window so there's no difference in UX:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜