1. John Niespodzianski
  2. PowerBuilder
  3. Monday, 3 May 2021 14:49 PM UTC

Hello!

Trying to work with the 2019 R3 web control enhancements.

I saw a solution posted here in the forums and I'm trying to get that to work as a starting point, but it's not triggering the local PB event from JavaScript.

My question is this - should it automatically fire the user event in the browser control when the JavaScript is executed in the browser?  Or do you have to always call EvaluateJavascriptSync() ?  The way I read it, the PB event would automatically be fired if it was properly registered and triggered from JavaScript.  Looking for clarity so I can get the basic concept working.

Here's the previous post that I'm working from; I set up the same HTML page, same ue_string event in the wb_1 control, set up RegisterEvent(), etc.

https://community.appeon.com/index.php/qna/q-a/webbrowser-control-and-registerevent#reply-27086

 

Thanks!

John

Uri Netanel Accepted Answer Pending Moderation
  1. Thursday, 8 July 2021 13:05 PM UTC
  2. PowerBuilder
  3. # 1

Hi John

As a work around for the event not firing automatically when the page is loaded you might try my response on another question here https://community.appeon.com/index.php/qna/q-a/new-webbrowser-event-to-know-navigate-is-finished#reply-28657 (you'd still have to call your event from powerbuilder, though)

 

Comment
There are no comments made yet.
John Niespodzianski Accepted Answer Pending Moderation
  1. Friday, 7 May 2021 12:42 PM UTC
  2. PowerBuilder
  3. # 2

Thanks everyone - I got it to work by moving the RegisterEvent() to NavigateStart.  I'd recommend the documentation be expanded to include Kai Zhao's excellent explanation in this thread; it wasn't clear in reading that it had to be registered a certain way.

If I add a button in the HMTL that fires JavaScript, it will trigger the user event in the browser control as expected. This is an awesome new feature that I will definitely be taking advantage of!

However, the one thing I cannot get to work is having the event fire automatically after the page loads.  I have tried various approaches -

  • body.OnLoad
  • addEventListener()
  • Explicitly calling the function at the bottom of the page

None work.  It will trigger the JavaScript (if I add an alert() it will pop up), but the PB event will never fire.  I'm assuming it is something similar to the RegisterEvent(), that it's a timing thing.  I'd love to be able to have a browser event fire automatically once the page is loaded w/o any user interaction (clicking a button, etc) - so if anyone has any solution or ideas on this, I'd appreciate your thoughts.

Thanks!

John

Comment
  1. Kai Zhao @Appeon
  2. Saturday, 8 May 2021 00:19 AM UTC
Hi John,



Glad to hear that and thanks for your valuable suggestion. We'll transfer this to our document team for consideration.



Regards,

ZhaoKai
  1. Helpful
  1. Miguel Leeuwe
  2. Saturday, 8 May 2021 07:48 AM UTC
You could try to call you powerbuilder browser event from the Vnavigationstatechanged" event, when cangoback = true. (I haven't tried this myself).

Another thing I've tried to use in the past, is the "navigationprogressindex" when progressindex = 100. The problem with this last event is that it`s being triggered multiple times with progressindex being 100. Only the last time it`s being triggered the page is fully loaded and there`s no way to know how many times the event will fire with progressindex having a value of 100. ZhaoKai explained to me that this has something to do with multiple frames like IFrame being loaded.

regards.
  1. Helpful
  1. Miguel Leeuwe
  2. Saturday, 8 May 2021 07:49 AM UTC
( "Vnavigationstatechanged" should be "navigationstatechanged")
  1. Helpful
There are no comments made yet.
Kai Zhao @Appeon Accepted Answer Pending Moderation
  1. Friday, 7 May 2021 03:16 AM UTC
  2. PowerBuilder
  3. # 3

Hi John,

Miguel’s explanation is correct.

The event can be triggered automatically by javascript like below in html file.
window.webBrowser.ue_getstring('Hi,PB!')

Please refer to the article below for details.
https://community.appeon.com/index.php/qna/q-a/webbrowser-control-and-registerevent#reply-27086

For the “it is not triggering the local PB event from JavaScript” issue, please make sure the event has been register successfully. PB application and WebBrowser are two processes. When you register the event in PB, WebBrowser might not have completed initializing yet and thus causes the issue. And when the navigatestart event in WebBrowser is triggered for the first time, it then can be regarded that WebBrowser has completed initializing, so it’s suggested to register event after the navigatestart event is triggered for the first time. For example, add the code below in the navigate event.

IF ib_RegisterEvent = FALSE THEN

Int li_rc
li_rc = wb_1.RegisterEvent ( "ue_process_message" )
IF li_rc =1 THEN
ib_RegisterEvent =TRUE
END IF
END IF

If there is still the issue, please provide a simple PB case to reproduce the issue for more study, thanks.

Regards,
ZhaoKai

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 5 May 2021 23:24 PM UTC
  2. PowerBuilder
  3. # 4

So in short, to at least try and answer your question (and please someone correct me if I'm wrong):

My question is this - should it automatically fire the user event in the browser control when the JavaScript is executed in the browser?  Or do you have to always call EvaluateJavascriptSync() ?  The way I read it, the PB event would automatically be fired if it was properly registered and triggered from JavaScript.  Looking for clarity so I can get the basic concept working.

Yes, once registered (at the right moment, like in NavigateStart event), the event should be fired. (look at my "ue_init()" event, fired from navigationstart event.

Also ignore the comment "// avoid running more than once since progressindex will be 100 like 5 times in a row ... (=reported bug)", that's because before this code was in the progress event, but it's no good as it's fired multiple times with arg value = 100.

You don't have to call the EvaluateJavascriptSync() every time to have your "event triggered".

Also to have your "event triggered", you don't use the  EvaluateJavascriptSync() function, but the "RegisterEvent()", function.

If you can't resolve your problem, please post your sample app and I (we) will have a look. It should be not too hard to solve, though I've experienced the control not to work until opening powerbuilder, killing it from the task manager and opening again. ...... :(

regards

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 5 May 2021 23:08 PM UTC
  2. PowerBuilder
  3. # 5

Hi John, 

I've probably been struggling with the same problems as you have. At the moment, I'm just very busy doing something that's robbing my sleep. For example see this: https://community.appeon.com/index.php/qna/q-a/webbrowser-control-and-registerevent#reply-27086

What I found is that the new webbrowser control is still a bit shaky, though it has improved a lot. I've been trying to get a TinyMCE HTML Editor to work and found that sometimes it's better to have pre-defined javascript functions in your html or js files, as compared to calling whatever they do with the powerbuilder EvaluateJavascriptSync() function, without having to have the existing functions in any file. (sometimes it works, sometimes it doesn't). It's a shame, because it would be a lot more secure to not have to have existing js functions (which can be modified by a user to do something else).

I'm sorry I don't have more time right now, but I'll add my code so you can see for yourself:

- When you run the app and type some code, there's a SAVE button on the toolbar that'll be enabled.

- If I remember well, that button has been programmed to call some power builder event.

 

The important files are:

- index.html

- ...\htmleditor\tinymcev4.9\plugin\tinymce\init-tinymce.js

- ...\htmleditor\tinymcev4.9\js\functions.js

- u_tinymce.event ue_init() called from 'navigationstart'.

 

You only have to register the events once.

When I have more time, I can help more, but give me a day or 2 (at the most).

See the attached Zip.

regards.

Attachments (1)
Comment
  1. Miguel Leeuwe
  2. Wednesday, 5 May 2021 23:13 PM UTC
LOL: Oh okay, THAT was the link you were looking at already... Please try if the attached sample can work for you.

regards,

MiguelL
  1. Helpful
There are no comments made yet.
John Niespodzianski Accepted Answer Pending Moderation
  1. Wednesday, 5 May 2021 22:10 PM UTC
  2. PowerBuilder
  3. # 6

Anyone?  I know a few folks have a working solution.  I just want to make sure I understand the mechanics correctly, and can produce a working prototype within the expectations.

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.