PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Having different hyperlinks on different words in text  (Read 2180 times)

PxPlus

  • Administrator
  • Diamond Member
  • *****
  • Posts: 1091
    • View Profile
Having different hyperlinks on different words in text
« on: July 04, 2018, 11:24:59 AM »
If you are looking to have different words with different hyperlinks in text, here is an easy way to do it:

This can be done using HTML and the *browser control.

Here is a sample non-Nomads program:

Code: [Select]
0010 DEF OBJECT h,@(1,1,40,10)="*browser"
0020 GOSUB Build_html
0030 h'document'write(html$)
0040 INPUT *
0050 END
0060 Build_html:
0070 LET html$="<html><body>"
0080 LET html$+="This is for <a href='https://forum.pvxplus.com' target='_blank'>forum</a>"
0090 LET html$+=" and this is for <a href='http://www.pvxplus.com' target='_blank'>pvxplus</a>"
0100 LET html$+="</body><html>"
0110 RETURN

To do this when using Nomads, create a COM control and select the Chromium browser then in the Post Create logic issue the object'Document'Write(...) method to load the HTML. If desired you can also have the browser control load the HTML from a file and use the Navigate2 method to display the text.

Now if you want to do something similar, but instead of true hyperlinks you want your application to be able to detect what the user clicked on and take some action, you can do something similar.

First off you need to create an object that will intercept the hyperlinks when clicked by the user.  Below is a object you can use:

Code: [Select]
! Menu event processor object
!
  def class "urlclick" create required
!
  property eventName$ ! Save area for the last click event
  local svTrigger
!
  function BEFORENAVIGATE2(*)BEFORE for event "BeforeNavigate2"
  end def
!
 ON_CREATE:
  enter oBrowser,ctlTrigger
  on event from oBrowser process _OBJ
  svTrigger=ctlTrigger
  exit
!
 BEFORE:
  enter *,U,*,*,*,*,C,err=*next
  def object U
  U$=U'val$
!
  eventName$=""
  if lcs(arg(U$,1,":"))="click" \
   then eventName$=arg(U$,2,":"),C=1;
        preinput svTrigger
  drop object U
  return 1

Save the above in urlclick.pvc.  This object will be called whenever a hyperlink is clicked and should that hyperlink contain "click:xxxxx" it will cancel the request (c=1) and save the click information.

Now try the following program:

Code: [Select]
  print 'CS',"Press F4 to Quit"
!
  button 10,@(0,0,1,1)="",opt="W"
  def object h,@(30,1,40,10)="[lcl]*browser"
  clicker=new("[lcl]urlclick",h,10) ! Set trigger
  gosub Build_html
  h'document'write(html$)
  while 1
  input *
  if ctl=4 \
   then break
  if ctl=10 \
   then print "You selected ",clicker'eventName$
  wend
  end
!
 Build_html:
  html$="<html><body style='font-family: calbri, arial;'>"
  html$+="This is for <a href='click:forum'>forum</a>"
  html$+=" and this is for <a href='click:pvxplus'>pvxplus</a>"
  html$+=" and this is for external  <a href='http://www.pvxplus.com' target='_blank'>pvxplus site</a>"
  html$+="</body><html>"
  return

This type of logic can also be used in Nomads by creating a dummy button (hidden if desired) and assigning logic to read and process the eventName$ based on the button being triggered.

Note: If using WindX you need to place the object file (urlclick.pvc) on the workstation.
« Last Edit: July 04, 2018, 06:01:18 PM by Mike King »