1. Bernhard Stoeter
  2. PowerBuilder
  3. Saturday, 7 December 2024 11:13 AM UTC

PowerBuilder PB2022R3 3356, Windows 10 and Window 11

Hi,

I want to execute jscript code with a window. I tried to use the webrowser (WebView2) EvaluateJavaScriptSync() function:

integer		li_rc
string		ls_Result, ls_ErrorMsg
webbrowser	lwb_Object

OpenUserObject( ref lwb_Object )
lwb_Object.Visible = FALSE

// without the MessageBox EvaluateJavaScriptSync(...) returns:
// 	-2 Failed to initialize the control and obtain the WebBrowser object. The WebView2 is invalid. 
// with the MessageBox EvaluateJavaScriptSync(...) returns:
// 	1 und ls_Result is the expected »{"type":"string","value":"lv PowerBuilder"}«
//MessageBox( "", "Continue?" )		// then it works

li_rc = lwb_Object.EvaluateJavaScriptSync( "'lv PowerBuilder';", ref ls_Result, ref ls_ErrorMsg )

CloseUserObject( lwb_Object )
destroy lwb_Object

Why is the call to MessageBox necessary to successfully execute EvaluateJavaScriptSync()? Is there a way to avoid the call to MessageBox or what can I do instead of calling it?
Of course, I can place an invisible webbrowser control on the window. But what is the effect of the call to MessageBox?

Thanks in advence,
Bernhard

Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Saturday, 7 December 2024 14:06 PM UTC
  2. PowerBuilder
  3. # 1

Hi Bernhard;

  After the OpenUserObject, try using a Yield() command just  before using the Evaluating() command in order to give the control time to initialize properly.  HTH 

Regards ... Chris 

Comment
  1. Bernhard Stoeter
  2. Wednesday, 11 December 2024 06:48 AM UTC
Hi Chris,



I take an instance wb, open it in window.open() and close itin window.close().

I was only wondering why me first approach did not work.



Regards Bernhard
  1. Helpful
  1. Kai Zhao @Appeon
  2. Wednesday, 11 December 2024 08:31 AM UTC
This is probably because the web page has not finished loading yet. Please move the code to the navigationcompleted event of WebBrowser control.
  1. Helpful 1
  1. Chris Pollach @Appeon
  2. Wednesday, 11 December 2024 12:56 PM UTC
Hi Bernhard;

If Kai's suggestion does not work, then please open a support ticket for the OpenUserObject approach

Regards ... Chris
  1. Helpful
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.