[Tutor] howto call DOM with python

Alan Gauld alan.gauld at btinternet.com
Fri Mar 2 01:17:47 CET 2007


"Ismael Farfán Estrada" <sulfurfff at hotmail.com> wrote

> I was wondering wheter someone knows how to use python to write
> a client-side scripts like if it were java, I want to get someting 
> like
> this working
> <html>
> <script type="text/python">
> window.alert("python")
> </script>
> </html>

You can do that in Internet Explorer provided you
a) Have the winall package installed and
b) Have turned on Activce Scripting so that Pythonm is
recognised as a language

> but nothing happens. I don't know javascript but this code works
> if I put javascript instead of python,

JavaScript is built in to most browsers (and VBScript is built into 
IE)
Any other scripting languages will need to be installed on the
target users machine. That is quite unlikely on the web so
most folks stick to JavaScript for browser based scripting.

Java applets will run if a JVM is installed (which it usually is)
and so you can write applets in Jython and compile them to
JVM code and they will work too.

> I've also tried with pythonscript python-source, etc

No, it has to be a valid interpreter. But the interpreter must also
be installed in the browser...

> hope you can help me, I'm using GNU/Suse, Opera, and Firefox for 
> test

I don't think you can make it work under Linux. The Jython applet
is your nearest option. You will be better learing the ninimum of
JavaScript IMHO. Try my tutorial as a quickl way in, especially
if you know Python...

Finally, you may be able to do what you want using the urllib
module to replace the browser entirely!

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld





More information about the Tutor mailing list