How to create a hyperlink within a text field?

J. Landman Gay jacque at hyperactivesw.com
Thu Feb 4 05:38:01 CET 2016


A little trick:

Create or import a transparent 1x1 pixel image. Hide it. Make each line 
in the table of contents into linked text. The html of each line looks 
like this:

<a>Chapter one</a>

In the body text of the field, place a marker character before the 
chapter heading. I'm using "#", like this:

#Chapter One

Then set the imagesource of char 1 of the line to the ID of the 
transparent image. You won't be able to see the first character after 
that but the text is still there. The htmltext of that line looks like this:

<p><img src="1036" char="#">Chapter One</p>

The line will be slightly indented by one pixel, but it shouldn't be 
noticeable. If you center the heading, it is imperceptible.

In the field script:

on linkclicked pURL
   put "#" before pURL
   put lineoffset(pURL, the formattedtext of me) into tLineNum
   set the scroll of me to the effective textheight of me * (tLineNum-1)
end linkclicked

If you choose a marker character that doesn't exist in the body text, 
lineoffset will always return the correct line.

-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com



More information about the use-livecode mailing list