AW: How to create a hyperlink within a text field?

BNig bernd.niggemann at uni-wh.de
Thu Feb 4 05:22:39 EST 2016


Tiemo Hollmann TB wrote
> Thanks Jacque,
> 
>>>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:

> Chapter one

> 
> 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>
<1036> 
> 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.

I like Jaques solution too because it is unequivocal because of the hash.

But Tiemo allows the user to change the width of the field, see his
crossposting to the forum
http://forums.livecode.com/viewtopic.php?f=9&t=26468

That is where Jaque's solution can fail because of wrapping.

This code is a small change to Jacques solution that should not fail since
words don't wrap

------------------------------------------------
on linkClicked pLink
   put "#" before pLink
   put the formattedText of me into tFormatData 
   
   put lineOffset(pLink,the text of me) into tFound
   
   -- check against the number of words in formattedText later
   -- they don't change compared to regular text
   put the number of words of line 1 to  tFound-1 of me +1 into tNoOfWords
   
   -- now get the number of lines to the first word of the found line
   put the number of lines of word 1 to tNoOfWords of tFormatData into
tApparentLines
   put (tApparentLines - 1) * the effective textHeight of me into tvScroll
   set the vScroll of me to tvScroll
end linkClicked
-------------------------------------------------

Kind regards
Bernd



--
View this message in context: http://runtime-revolution.278305.n4.nabble.com/How-to-create-a-hyperlink-within-a-text-field-tp4700650p4700711.html
Sent from the Revolution - User mailing list archive at Nabble.com.




More information about the use-livecode mailing list