PxPlus User Forum

Twitter Twitter Twitter

Author Topic: *browser child object beforenavigate2() event not triggering  (Read 1163 times)

Josh Fake

  • Member
  • **
  • Posts: 13
    • View Profile
    • Earnest & Associates
I currently am trying to get the BeforeNavigate2() event to trigger code within a child object, so as in shell.explorer.2 make any necessary changes if allowed in the *browser object to the variant objects values.

My dilemma is that I have code that I can switch between *browser or shell.explorer.2 and with a child object waiting for the beforeNavigate2() event to be triggered, yet it will not be triggered inside of *browser but will within shell.explorer.2.  Based on what I have read on other posts, the help for *browser, and the presentation at Direxions 2018, this should work interchangeably without any issues.

Links I have mainly based this off of, thanks Jeff Wilder/Devon for the examples!!
https://forum1.pvxplus.com/index.php?topic=226.msg626#msg626
https://forum1.pvxplus.com/index.php?topic=82.msg138#msg138

My qnd for this is as follows whichIt will allow you to switch between shell.explorer.2 and *browser on line 120. The on the following line will allow you to optionally select how you want to navigate to open/navigate to a page/url via a local file, an url, or write the html directly (only works with *browser)


0010 ! sig.test.2
0100 ! configure url
0111 final_url$="https://www.blank.org/blank.html"
0115 html_file$="blank.html",html$=fnget_html$(html_file$)
0120 use_shell_explorer=0 ! 0 - use *browser object / 1 - use shell.explorer.2 object
0125 post_type$="use_url" ! "use_url","use_html_file","use_html_string"
0200 ! define window
0205 win_x=1,win_y=1,win_w=70,win_h=41
0210 win_title$="Testing of BeforeNavigate()"
0215 ! print 'dialogue'(int(win_x),int(win_y),win_w,win_h,win_title$,'CS'+'C0') ! create new window
0300 ! add *browser/shell.explorer.2 to local screen
0310 def object x,@(0,0,win_w,win_h)="[lcl]"+tbl(use_shell_explorer,"*browser","shell.explorer.2")
0315 y=new("[lcl]cseawebui",x)
0350 ! now configure y events to occur based off of standard x (browser) events
0355 ! on event from x process y ! this is configured inside of child object (y) within on_create routine
0360 on event "BeforeNavigate2" from x preinput 100
0365 on event "DownloadComplete" from x preinput 101
0400 !
0405 switch post_type$
0410 case "use_url"
0415 x'navigate2(final_url$) ! if shell.explorer.2 beforenavigate2 code is executed, browser it is not
0420 break
0430 case "use_html_file"
0435 tmp_file$="file://"+sub(lwd,dlm,"/")+tbl(mid(lwd,-1)=dlm,"/","")+html_file$
0440 x'navigate2(tmp_file$)
0445 break
0450 case "use_html_string"
0455 x'document'write(html$) ! will error if using shell.explorer.2 but still will not fire beforenavigate2 if *browser
0460 break
0470 default ; escape ! did not load xml invalid response
0480 end switch
0490 escape
0900 !
0905 escape ! do not even bother wtih the following until i can get beforenavigate2 to function with *browser
0910 drop object y ! cseawebui.pvc
0915 drop object x ! *browser/shell.explorer.2
30000 def fnget_html$(local file$)
30005 local tmp$,response$,opened
30010 try
30015 open (hfn)file$; opened=1
30020 read record (lfo,end=*next)tmp$; response$+=tmp$; goto *same
30025 catch ; response$="<failed load>"
30035 finally ; if opened then close (lfo)
30040 end_try
30045 return response$
30050 end def

After instantiating the *browser object, I open my child "object" to halt code when an event inside of the browser is triggered.  Instantiated on line 315.
0010 ! CSEAWEBUI.pvc
1000 ! ^1000,5
1005 def class "CSEAWEBUI"
1010 property postdata$
1020 property browser_type$
1080 function beforenavigate2(*)ON_BEFORE_NAVIGATE for event "BeforeNavigate2" ! *
1090 end def
2000 ON_CREATE:
2005 enter o_browser
2010 on event from o_browser process _obj
2015 browser_type$=try(o_browser'pvxname$,"*browser")
2020 msgbox "cseawebui - on_create"+sep+"Using: "+browser_type$,"event triggered","!"
2090 exit
3000 ON_BEFORE_NAVIGATE:
3005 enter pdisp,url,flags,targetframename,postdata,headers,cancel,err=*next
3006 msgbox "cseawebui - BEFORENAVIGATE2()"+sep+"Using: "+browser_type$,"event triggered","!"
3010 def object url
3015 def object flags
3020 def object targetframename
3025 def object postdata
3030 def object headers
3050 msgbox "url="+url'val$+sep+"flags="+str(flags'val)+sep+"targetFrameName="+targetframename'val$+sep+"headers="+headers'val$+sep+"postData="+postdata'val$,"INFO"
3090 exit


Using the code above when setting the qnd to use shell.explorer.2 beforenavigate2() event will trigger as desired and the message box will appear.  But within *browser it will not.  Is there anyone that can assist in pointing me how to get the beforenavigate2() event to trigger in *browser?  I have been spinning my wheels on this one.

Any and all help will be greatly appreciated.


Devon Austen

  • Administrator
  • Diamond Member
  • *****
  • Posts: 382
  • Don’t Panic
    • View Profile
    • PVX Plus Technologies
Re: *browser child object beforenavigate2() event not triggering
« Reply #1 on: May 20, 2021, 12:33:15 PM »
Your code tries to handle the event twice. Once in the object and also by generating a CTL 100.

Do you not get either handler triggered or is it just the object handler that is not triggered?

Try commenting out line 360 and 365 to see if the object handler starts working.
Principal Software Engineer for PVX Plus Technologies LTD.

Josh Fake

  • Member
  • **
  • Posts: 13
    • View Profile
    • Earnest & Associates
Re: *browser child object beforenavigate2() event not triggering
« Reply #2 on: May 20, 2021, 01:43:49 PM »
Devon,

Thanks for the response and yes if I removed those two lines that set a ctl value when an event is also triggered, it will execute the child objects beforeNavigate2() event.  But there is a caveat to this which is why those are needed unless there is a better way?

After the code I produced, it also has the following code waiting for an event to be triggered from the web page itself by the end user:
1000 ! loop unti user completes web navigation or closes window
1005 while 1
1010 obtain 'ME',*,'MN'; _ctl=ctl,_eom$=eom ! get input
1020 if cse(_ctl,100,101) then escape
1085 if cse(_ctl,104,4,-1999) then cancel=1; break
1090 wend


As you can see I am querying for those ctl values either 100 or 101 based on the event that occurs by user interaction within the web page itself.  Either by closing the window or by selecting one of the three buttons themselves. I cannot figure out how to show this directly within the post, but i have attached a screenshot.

So how within the code above can I have it wait in the main program for one of those events to be triggered as well as execute the BeforeNavigate2() event inside the child object?  I need both to occur using the *browser object.

The reason I need it to trigger the escape within the while loop as I have to execute javascript on its response to retrieve a "message" based on a listener.

Thanks again for your help.

« Last Edit: May 20, 2021, 01:46:47 PM by Josh Fake »

Devon Austen

  • Administrator
  • Diamond Member
  • *****
  • Posts: 382
  • Don’t Panic
    • View Profile
    • PVX Plus Technologies
Re: *browser child object beforenavigate2() event not triggering
« Reply #3 on: May 20, 2021, 02:07:15 PM »
My first though would just to add the following line to your logic in your beforenavigate2 method of your object

PREINPUT 100

Then add a DownloadComplete method to the object that just does

PREINPUT 101
Principal Software Engineer for PVX Plus Technologies LTD.

Josh Fake

  • Member
  • **
  • Posts: 13
    • View Profile
    • Earnest & Associates
Re: *browser child object beforenavigate2() event not triggering
« Reply #4 on: May 20, 2021, 03:10:37 PM »
Devon,

Thank you, it worked like a charm! I am not familiar with the preinput command as I am assuming the drivers for the application I work in handles those for us.  I was going off code that was written before with the shell.explorer.2 object.

Thanks Again!!