MacHTTP's way of implementing imagemaps is to pass the query parameters into a script program written in AppleScript . By default, MacHTTP recognises any filename ending with .script to be an AppleScript program, which it then runs with the correct parameters, and which returns the result directly to the remote client.
Unlike NCSA or CERN HTTPDs for UNIX systems, MacHTTP does not come bundled with a special imagemap program or map definition syntax for defining hot spots in images. Until recently, crafting your own script using AppleScript was your only option. However, a program called MacImage has recently been released, which is very similar to NCSA's imagemap program described below, and means the DIY approach is not the only option for MacHTTP users.
Before MacImage, implementation of complex imagemaps using
MacHTTP was quite difficult. You had to write your own map script
for every active map you want to set up. For simple maps, this isn't
too difficult if you use example below as a template for your own
script. If you haven't met AppleScript before, ignore the first part of the
example and just modify the last bit after the comment `` --now
we've ready to actually do something.''
The best way to do active maps is to make use of HTTP's redirection
using the ``found'' response. This lets the WWW server tell the
client where to go to find the actual data it was looking for. The
following AppleScript shows one way this can be done (the
...
pair indicates this should
really be one line).
set crlf to (ASCII character 13) & (ASCII character 10)
--this is the header we'll return for active areas of the map
set found_header to "HTTP/1.0 302 FOUND" & crlf &
![]()
"Server: MacHTTP" & crlf & "MIME-Version: 1.0" & crlf
--this is the header we'll return for errors
set error_header to "HTTP/1.0 400 Bad Request" & crlf &
![]()
"Server: MacHTTP" & crlf & "MIME-Version: 1.0" & crlf &
![]()
"Content-Type: text/html" & crlf & crlf
--this is the header we'll return for inactive areas of the map
set unfound_header to "HTTP/1.0 404 OK" & crlf &
![]()
"Server: MacHTTP" & crlf & "MIME-Version: 1.0" & crlf &
![]()
"Content-Type: text/html" & crlf & crlf
--parse the arguments to the script
if http_search_args = "" then
return error_header & "<h1>Bad Request</h1>" & crlf &
![]()
"Insufficient arguments to image map script"
else
set comma to offset of "," in http_search_args
set theLast to count http_search_args
set x to (text 1 thru (comma - 1) of http_search_args) + 0
set y to (text (comma + 1) thru theLast of http_search_args) + 0
end if
--now we've ready to actually do something
if x < 16 and y < 16 then
return found_header & "Location: http://eek/page1.html" & crlf
else if x > 10 and x < 20 and y > 10 and y < 20
return found_header & "Location: http://eek/page2.html" & crlf
else
return unfound_header & "<h1>Not found</h1>" & crlf &
![]()
"Nothing found at this map location" & crlf
end if
However this is much less elegant than the imagemap mechanism that NCSA's server provides on Unix systems.