Making a clickable part of an image reveal text

Harlowe 3.3.3.

I’m using this command to make it so that if you click on something it reveals text.

(click: ?cheese)[Cheese]

That makes the word cheese appear.
And I can do this with an image and it works:

[<img src="beef.jpg"/>]<cheese|
(click: ?cheese)[Cheese]

But not with only PART of an image that’s clickable. Like so:

[<img src="beef.jpg" usemap="#image-map">

<map name="image-map">
    <area target="" alt="" title="" href="" coords="520,246,848,665" shape="rect">
(click: ?cheese)[Cheese]

This does cause the text, in this example “cheese,” to appear–but only for a split second, before Twine forcibly reloads the passage.

Anyone know a way to make this work?


The problem is that the image map has an empty href attribute and that causes it to be a link that refreshes the passage (outside of Harlowe’s normal behaviour).

If you remove that attribute, it should work fine. If removing the href causes accessibility issues, you can always put href="javascript:void(0)". It’s also good to wrap the hook around just the map coordinate you want to trigger.

This is a working version, similar to your code example, with 2 clickable areas:

{<img src="" usemap="#image-map"/>
<map name="image-map">
	[<area target="" alt="" title="" href="javascript:void(0)" coords="0,0,200,150" shape="rect">]<top|
    [<area target="" alt="" title="" href="javascript:void(0)" coords="0,150,200,300" shape="rect">]<bottom|
(click: ?top)[Top Half]
(click: ?bottom)[Bottom Half]

I used a free image so you can copy and paste this code and see it in action. Also, I only tested this in Firefox.

Let us know if you have any other questions.

Oh, and welcome to the community! :slight_smile:


Oh, okay…yeah, I just copied that code from a website that lets you easily generate image maps without really understanding everything there. Works now. Thanks!