Tcl/Tk Plugin V2 Javascript Test Applet

[ Back to the V2 Tclets Demos ]

Source

Here is the source (annotation coming soon):
message .m -width 200 -textvariable msg
pack .m -side bottom -fill x -expand 1
proc bgerror {msg} {
    set ::msg "Error: $msg"
}
if {[catch {policy javascript} errMsg]} {
    set msg "Sorry but your configuration does not allow\
	    this tclet to use the javascript security policy ($errMsg)."
    append msg "\nYou are using the tcl plugin $plugin(patchLevel)."
} else {
    button .b -text "Click Me!" -command doit
    pack .b -pady 10
    set msg "loading and image using getURL..."
    set count 0
    after idle {
	set data [browser::getURL tcllogo1.jpg]
	set msg "done loading !\nready for user click !"
    }
    proc doit {} {
        global count msg
	set topname top$count
	incr count
	set msg "making a new undecorated window using javascript..."; update
	after 700
	browser::javascript [subst \
	    {window.open("","$topname","menubar=no,width=400,height=170")}]\
	    "display $topname"
    }
    proc display {topname args} {
	global data msg
	set msg "done... opening a new stream of time image/jpeg"; update
	after 700
	set f [browser::openStream $topname image/jpeg]
	set msg "...writing the image data..."; update
	browser::writeToStream $f $data
	browser::closeStream $f
	set msg "all done !\nready for new click!"
    }
}

(Reminder: To see those demos you need Tcl/Tk Plugin Version 2.0.3 or later and Netscape Navigator/Communicator or Internet Explorer).