Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How far can I go with JavaScript?

I need to do as much as possible on the client side. In more details, I would like to use JavaScript to code an interface (which displays information to the user and which accepts and processes response from the user). I would like to use the web serve just to take a date file from there and then to send a modified data file back. In this respect I would like to know if the following is possible in JavaScript:

  1. Can JavaScript read content of a external web page? In other words, on my local machine I run JavaScript which reads content of a given web page.

  2. Can JavaScript process values filled in a HTML form? In other words, I use HTML and JavaScript to generate an HTML form. User is supposed to fill in the form and press a "Submit" button. Then data should be sent to the original HTML file (not to a web server). Then this data should be processed by JavaScript.

  3. In the very end JavaScript will generate a local data-file and I want to send this file to a PHP web server. Can I do it with JavaScript?

  4. Can I initiate an execution of a local program from JavaScript. To be more specific, the local program is written in Python.

I will appreciate any comments and answers.

like image 373
Roman Avatar asked Feb 23 '10 11:02

Roman


1 Answers

  1. It could technically, but can't in reality due to the same origin policy. This applies to both reading and writing external content. The best you can do is load an iframe with a different domain's page in it - but you can't access it programmatically. You can work around this in IE, see Andy E's answer.

  2. Yes for the first part, mmmm not really for the second part - you can submit a form to a HTML page and read GET arguments using Javascript, but it's very limited (recommended maximum size of data around 1024 bytes). You should probably have all the intelligence on one page.

  3. You can generate a file locally for the user to download using Downloadify. Generating a file and uploading it to a server won't be possible without user interaction. Generating data and sending it to a server as POST data should be possible, though.

  4. This is very, very difficult. Due to security restrictions, in most browsers, it's mostly not possible without installing an extension or similar. Your best bet might be Internet Explorer's proprietary scripting languages (WScript, VBScript) in conjuction with the "security zones" model but I doubt whether the execution of local files is possible even there nowadays.

like image 92
Pekka Avatar answered Oct 07 '22 01:10

Pekka