Way to determine if button is pressed in browser
Gary Rathbone
gary.rathbone at btclick.com
Mon Jan 27 17:57:00 EST 2003
Ok, I've stripped out my 'extra' bits for simplicity, so here goes...
I've got a stack with a single button 'Start' and a field 'tfld'.
In the start button the script is...
----------------------------------------------------
on mouseup
put "" into fld "tfld"
--kill any existing sockets (can be used for a stop button)
get the OpenSockets
repeat with c=1 to the number of lines in it
close socket (line c of it)
end repeat
--start to accept connections
accept connections on port 8181 with message "wRequest"
end mouseup
on wRequest skt
set the socketTimeoutInterval to 20000
read from socket skt for 1 line
put it into fld "tfld"
close socket skt
end wRequest
-----------------------------------------------------
I've then got a web page at http://www.garyrathbone.net/revclick.htm
Which consists of
-----------------------------------------------------
<html>
<head>
<title>ClickRev</title>
<script language="JavaScript">
function fClick(tStr){
tReq="http://127.0.0.1:8181/$"+tStr+"$"
document.tfake.src=tReq}
</script>
</head>
<body>
<p> </p>
<p> </p>
<p align="center">
<img src="" height="0" width="0" border="0" name="tfake">
<img src="http://www.GaryRathbone.net/images/pics/prop.gif"
onClick="fClick('Hello World')"> </p> </body> </html>
-----------------------------------------------------
Click 'Start' on the stack. When the button (in this case an image) is
clicked on the web page the Javascript tries to load a 'fake' image from ip
127.0.0.1 on port 8181. This is the stack on your local machine. The stack
takes the 'request' in this case the string 'Hello World' (so you can
actually pass parameters) and puts it in the field "tfld" (Obviously you can
parse this etc....) The socket is then killed so the browser doesn't end up
waiting.
It's a bit of a cheat, but it works fine. It can be improved in just about
every direction possible, but I hope it provides a start.
Regards
Gary Rathbone
-----------------------------------------------------
More information about the use-livecode
mailing list