Re: [Dorset] Client Side Scripting of Web Pages

2013-10-25 Thread Terry Coles

On 24/10/13 17:22, Terry Coles wrote:
So here's the question. Are there numerous ways to do this and if so, 
does every browser have its own way?

OK, so we discussed this further at work and homed in on the real question:

I understand that all browsers speak Javascript, so a page containing 
js, just gets executed.  What if the script is written in PERL, PHP or 
even TCL or Python?  Presumably the page includes a mime type, but how 
does the browser know what package to use to execute the code.  We 
appreciate that the OS knows what to do with these languages because its 
file associations settings, but my colleague believes that he has 
monitored all of the activity when a browser loads a page with 
referenced scripts on it and the browser never calls the OS.


What have we missed?

Terry
--
Next meeting:  Bournemouth, Tuesday, 2013-11-05 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread on mailing list:  mailto:dorset@mailman.lug.org.uk
How to Report Bugs Effectively:  http://goo.gl/4Xue


Re: [Dorset] Client Side Scripting of Web Pages

2013-10-25 Thread Ralph Corderoy
Hi Terry,

 Terry Coles wrote:
  I understand that all browsers speak Javascript,

Except those that don't, e.g. lynx(1).  :-)

  so a page containing js, just gets executed.  What if the script is
  written in PERL, PHP or even TCL or Python?  Presumably the page
  includes a mime type, but how does the browser know what package to
  use to execute the code.

Well, the browser has a list of MIME types and how to handle them for
other things, e.g. audio formats.  You can edit it to use external
programs, for example.

But are you getting confused between code that's shipped as part of, or
referenced by, a HTML web page and code that responds to a HTTP request
from a browser on the server?  That back-end code can be written in
anything and the browser doesn't know or care.

Andrew Montgomery-Hurrell wrote:
 Most browsers just fail if you use any language other than javascript.

There's a version of Chromium that supports Dart natively AIUI.  For
other browsers, you load some Javascript that can handle the Dart.

https://www.dartlang.org/docs/tutorials/connect-dart-html/#about-html-code

script type=application/dart src=mini.dart/script
script src=packages/browser/dart.js/script

 I'm not entirely sure browsers even expose a useful enough API to be
 able to develop a useful plugin to do that.

I think they do?  I've vague recollections of being able to add a Python
interpreter to Internet Explorer some years ago when web scripting
languages first made an appearance.

Cheers, Ralph.

-- 
Next meeting:  Bournemouth, Tuesday, 2013-11-05 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread on mailing list:  mailto:dorset@mailman.lug.org.uk
How to Report Bugs Effectively:  http://goo.gl/4Xue


Re: [Dorset] Client Side Scripting of Web Pages

2013-10-25 Thread Andrew Montgomery-Hurrell
Some browsers do expose an API allowing these things, but my point is more
that I'm not convinced they provide anything that allows someone to add in
support for other languages that is useful in anyway beyond simple toys.
Regarding Python in the browser, this site has some useful info:
https://wiki.python.org/moin/WebBrowserProgramming

I'm wondering as to _why_ you even want to run scripts in another language
client-side. Any such language would (assuming the browser support API also
sandboxes it's code) be limited to only effecting changes in the browser
environment, so there isn't really any utility to using another language
over javascript. If you want to be able to run scripts that do other things
outside of that sandbox (such as a script that runs an application on the
user's computer and displays it's output in the browser), then there are a
whole bunch of security implications there which need to be considered.


On 25 October 2013 14:26, Ralph Corderoy ra...@inputplus.co.uk wrote:

 Hi Terry,

  Terry Coles wrote:
   I understand that all browsers speak Javascript,

 Except those that don't, e.g. lynx(1).  :-)

   so a page containing js, just gets executed.  What if the script is
   written in PERL, PHP or even TCL or Python?  Presumably the page
   includes a mime type, but how does the browser know what package to
   use to execute the code.

 Well, the browser has a list of MIME types and how to handle them for
 other things, e.g. audio formats.  You can edit it to use external
 programs, for example.

 But are you getting confused between code that's shipped as part of, or
 referenced by, a HTML web page and code that responds to a HTTP request
 from a browser on the server?  That back-end code can be written in
 anything and the browser doesn't know or care.

 Andrew Montgomery-Hurrell wrote:
  Most browsers just fail if you use any language other than javascript.

 There's a version of Chromium that supports Dart natively AIUI.  For
 other browsers, you load some Javascript that can handle the Dart.


 https://www.dartlang.org/docs/tutorials/connect-dart-html/#about-html-code

 script type=application/dart src=mini.dart/script
 script src=packages/browser/dart.js/script

  I'm not entirely sure browsers even expose a useful enough API to be
  able to develop a useful plugin to do that.

 I think they do?  I've vague recollections of being able to add a Python
 interpreter to Internet Explorer some years ago when web scripting
 languages first made an appearance.

 Cheers, Ralph.

 --
 Next meeting:  Bournemouth, Tuesday, 2013-11-05 20:00
 Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
 New thread on mailing list:  mailto:dorset@mailman.lug.org.uk
 How to Report Bugs Effectively:  http://goo.gl/4Xue




-- 
Andrew Montgomery-Hurrell
Professional Geek
Blog: http://darkliquid.co.uk
Twitter: http://twitter.com/darkliquid
Fiction: http://www.protagonize.com/author/darkliquid
-- 
Next meeting:  Bournemouth, Tuesday, 2013-11-05 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread on mailing list:  mailto:dorset@mailman.lug.org.uk
How to Report Bugs Effectively:  http://goo.gl/4Xue


Re: [Dorset] Client Side Scripting of Web Pages

2013-10-25 Thread Ralph Corderoy
Hi Terry,

 So if we want to use a browser to execute a script that isn't js,
 there's no reliable way to do it that would work across all platforms
 / browsers.

Add some Javascript to interpret it or produce equivalent Javascript on
the fly.  :-)

You alternative is to also ship a web server specific to your task that
they run on their local machine and your web pages access on its port
using localhost.  This can be written in anything that will run on the
platforms you support, e.g. Python, Go, ...

An example is Python's SimpleHTTPServer module, which is a library that
can be imported into your own code;  it can also be run as a standalone
program which makes it serve the files rooted at the current directory.

In one window...

$ ls
hello.html  pi.txt
$ python /usr/lib/python2.6/SimpleHTTPServer.py
Serving HTTP on 0.0.0.0 port 8000 ...

In another...

$ curl -sS http://localhost:8000/pi.txt
3.14159265358979323844
$ lynx -dump http://localhost:8000/hello.html
   Man who set type, risk becoming galley slave.
$

It maps file suffixes onto the MIME types for the Content-type header.

$ curl -sSI http://localhost:8000/hello.html
HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/2.6.6
Date: Fri, 25 Oct 2013 13:42:50 GMT
Content-type: text/html
Content-Length: 123
Last-Modified: Fri, 25 Oct 2013 13:40:30 GMT

$ curl -sSI http://localhost:8000/pi.txt
HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/2.6.6
Date: Fri, 25 Oct 2013 13:42:56 GMT
Content-type: text/plain
Content-Length: 23
Last-Modified: Fri, 25 Oct 2013 13:39:06 GMT

$

Your server would run its own logic rather than just serve static files.

Cheers, Ralph.

-- 
Next meeting:  Bournemouth, Tuesday, 2013-11-05 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread on mailing list:  mailto:dorset@mailman.lug.org.uk
How to Report Bugs Effectively:  http://goo.gl/4Xue


Re: [Dorset] Client Side Scripting of Web Pages

2013-10-25 Thread Ralph Corderoy
Hi Andrew,

 I'm not convinced they provide anything that allows someone to add in
 support for other languages that is useful in anyway beyond simple
 toys.

They would be as useful as Javascript, I imagine.

 I'm wondering as to _why_ you even want to run scripts in another
 language client-side.

Will, things like:  corporate demands;  lack of Javascript knowledge
in-house;  numerical code would like integers, not just floating-point
doubles;  dislike of Javascript -- something drove Coffeescript and Dart
to exist  :-).

 Any such language would (assuming the browser support API also
 sandboxes it's code) be limited to only effecting changes in the
 browser environment

Just like Javascript, yes.  They just don't want to use it or already
have lots of useful library code in another language.

Cheers, Ralph.

-- 
Next meeting:  Bournemouth, Tuesday, 2013-11-05 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread on mailing list:  mailto:dorset@mailman.lug.org.uk
How to Report Bugs Effectively:  http://goo.gl/4Xue


Re: [Dorset] Client Side Scripting of Web Pages

2013-10-25 Thread Terry Coles

Thanks Andrew and Ralph,

I'll report back to my colleagues on Wednesday (I'm out Mon / Tues next 
week) and see what the consensus is.  Stand by for the next thrilling 
instalment :-)


For your information, I'm more of a go-between here, but my colleagues 
want to be able to create documentation / tools that customers can view 
with a standard browser on any platform.  We have no prior experience of 
javascript, but we do of quite a few other scripting languages, (such as 
TCL), so there are some cost savings to be had if we write / cull code 
that we already have rather than writing something completely from 
scratch in an unfamiliar language.


We also have tools that can generate code automatically from key 
parameters / attributes, but they don't do javascript :-(  A reliable 
way for the browser to invoke the necessary tool would be ideal, but 
maybe something server side could work.  however, we would have to ship 
the server because these tools do not always have access to the internet.


Terry

On 25/10/13 15:31, Andrew Montgomery-Hurrell wrote:

That makes sense. There are a few projects (like PyJS or phpjs) that can
compile a subset of another language into javascript which might be usable
in those scenarios, but you lose the benefits of, say, proper numerical
typical, etc in that case since it's still javascript at the end of the
process.


On 25 October 2013 14:59, Ralph Corderoy ra...@inputplus.co.uk wrote:


Hi Andrew,


I'm not convinced they provide anything that allows someone to add in
support for other languages that is useful in anyway beyond simple
toys.

They would be as useful as Javascript, I imagine.


I'm wondering as to _why_ you even want to run scripts in another
language client-side.

Will, things like:  corporate demands;  lack of Javascript knowledge
in-house;  numerical code would like integers, not just floating-point
doubles;  dislike of Javascript -- something drove Coffeescript and Dart
to exist  :-).


Any such language would (assuming the browser support API also
sandboxes it's code) be limited to only effecting changes in the
browser environment

Just like Javascript, yes.  They just don't want to use it or already
have lots of useful library code in another language.

Cheers, Ralph.

--
Next meeting:  Bournemouth, Tuesday, 2013-11-05 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread on mailing list:  mailto:dorset@mailman.lug.org.uk
How to Report Bugs Effectively:  http://goo.gl/4Xue







--
Next meeting:  Bournemouth, Tuesday, 2013-11-05 20:00
Meets, Mailing list, IRC, LinkedIn, ...  http://dorset.lug.org.uk/
New thread on mailing list:  mailto:dorset@mailman.lug.org.uk
How to Report Bugs Effectively:  http://goo.gl/4Xue