4

Suppose, I've a FTP URL (ftp://xyz.org/file.zip). If I type this in the browser manually, then hit enter, the browser will start to download the file.zip and would ask me save it on harddisk.

My question is: Is it possible to write a script in JavaScript, which when run should download the file with all these options (separately)?

  • in a new window?
  • in a new tab in the same window?
  • without opening a new window or tab?
2
  • 6
    window.location = 'ftp://xyz.org/file.zip'; Commented Mar 17, 2011 at 11:40
  • 2
    I don't see why not. Have you tried window.open("ftp://....") or window.location = "ftp://..." in various browsers? Commented Mar 17, 2011 at 11:41

2 Answers 2

8

new window or new tab is controlled by the user's preference, and you can't override that. But to open your URL in a new tab/window you would use

window.open('ftp://xyz.org/file.zip');

to request it without opening a new window just

window.location = 'ftp://xyz.org/file.zip';
Sign up to request clarification or add additional context in comments.

2 Comments

If we use window.open(), can we give the size of window as well?
@Nawaz, you can but I don;t see the point at all as the user is just going to get a "download to..." dialog.
2

At the most basic just make a link like this:

<a href="ftp://...." target="_blank">Download in new tab/window</a>

In JS just open a window with that url.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.