How to download a file on Android and IOS without using PlugIn?

How can I download a file from a URL and display the "Open with..." option on Android and IOS?

I made JavaScript code that does this. I put the code to run in the OnClick event of a button. However, on the smartphone itself, it presents the error (a request error), sometimes even terminating the application. When I run in the WEB environment (android simulator) it works normally, it downloads the file.

Theoretically it is a simple Javascript code that creates a LINK dynamically and clicks on this link. This way, it would have a standard behavior to click on a link in the browser, right?

What am I doing wrong here?

The error message is as follows: "There was an error processing your request."

Can someone help me?

At first this command worked well on Android: ('external: https: //AnyURL.pdf', '_system');

But, unfortunately, on the Iphone it didn't work. Is it possible to do something like that in IOS?