Page 1 of 1

Problem with example from help file

PostPosted: Thu Jan 19, 2012 9:01 am
by dpayer
I am attempting to get something from the page displayed in the webbrowser object. I am getting errors so I go to the basics:

Win7, IE8
In Advanced/Security section of Internet Options, I allow active content to run in files on my computer.

I create a webbrowser object, I remove check for Enhanced Security.

I create a button and have as the Action the sample from the help file:

Example:
This example executes NeoBook's AlertBox action:

<script language="JScript">
function DoExec() {
window.external.nbExecAction( 'AlertBox "Hello" "Hello from the Web Browser!"' );
}
</script>


using this syntax:
Code: Select all
BrowserExecScript "WebBrowser2" "<script language=[#34]JScript[#34]>||function DoExec() {||  window.external.nbExecAction( 'AlertBox [#34]Hello[#34] [#34]Hello from the Web Browser![#34]' );||}||</script>" "JScript"

I get the following error when I test the script, when I run the app from the beginning and when I compile the app:

Could not complete the operation due to error: 80020101


Any insights?

David Payer

If you....

PostPosted: Thu Jan 19, 2012 9:53 am
by virger
FROM COSTA RICA
PURA VIDA
--------------
And if you try this!??
(it's a button)
---------------------------
{NeoBook 5 Objects}
NeoBookVer=5.70
ObjectType=3
Name=BtIE
X=174
Y=70
W=70
H=30
Anchor=0
Text=Internet
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=BrowserLoadFromStr "WEB" "<html>|<script language=[#34]JScript[#34]>|function DoExec() {| window.external.nbExecAction( 'AlertBox [#34]Hello[#34] [#34]Hello from the Web Browser![#34]' );|}|</script>|<body onload=[#34]DoExec()[#34]>|HELLO|</body>|</html>"
LineColor=0
LineWidth=2
LineStyle=0
FillColor=16304352
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=10

Re: If you....

PostPosted: Thu Jan 19, 2012 10:31 am
by dpayer
Virgir, Thank you for the example. That will cause a NB alertbox to pop up. I will see if I can use nbExecAction instead of BrowserExecScript.

My ultimate goal is to execute an existing JS function on a page and return the value generated into NB.

David P.

Partial solution

PostPosted: Thu Jan 19, 2012 11:08 am
by dpayer
In the original post I mentioned problems and therefore the test that also didn't work right. Here are the details and one work around I found.

I am attempting to get TinyMCE to work in a WebBrowser object to create an HTML editor :)

It works fine, loading their sample scripts from file. They even have a link on the bottom of the sample for getting the HTML generated.

In my attempt to get this using a button to execute a script in the browser I have (with failure) tried this:
Code: Select all
BrowserExecScript "WebBrowser1" "<script language=[#34]JScript[#34]>||function GetRawHTML() {||RawHTMLdata = (tinyMCE.get('elm1').getContent());|window.external.nbSetVar( '[RawHTML]', RawHTMLdata );|  }||</script>

the code: (tinyMCE.get('elm1').getContent() is the function provided in TinyMCE via a link on the sample page.

I also tried (unsuccessfully) using a standard JS function of getElementByID:
Code: Select all
window.external.nbSetVar( '[rawhtml]', document.getElementById('elm1'));

which gave the same error in the original post.

The one (non NB) way that worked was the link in the sample page which called the TinyMCE function:
Code: Select all
<a href="javascript:;" onclick="alert(tinyMCE.get('elm1').getContent());return false;">[Get contents]</a>

it displays the code of the page in a JS alertbox.

Well, guess what, I see I can do something similar with NB with a link in the webpage that I can get back as a NB variable! Using a separate Alertbox to display that variable, I see it works.
Code: Select all
<a href="neobook:;" onclick="window.external.nbSetVar( '[rawHTML]', (tinyMCE.get('elm1').getContent()));return false;">[Get contents via NB]</a>

Now I need how to control this with NB functions directly. It appears I must not be getting the syntax of using the BrowserExecScript right.

PostPosted: Thu Jan 19, 2012 12:10 pm
by Neosoft Support
Could not complete the operation due to error: 80020101


That's Microsoft's general all purpose error message for almost any error in a script. It's maddeningly unhelpful, but usually means that there is a syntax error somewhere.

Try something like this:

Code: Select all
BrowserExecScript "WebBrowser2" "window.external.nbExecAction( 'AlertBox [#34]Hello[#34] [#34]Hello from the Web Browser![#34]' );" "JScript"

PostPosted: Thu Jan 19, 2012 5:36 pm
by Tony Kroos
dpayer wrote:My ultimate goal is to execute an existing JS function on a page and return the value generated into NB.

Attach a function to any event (click, load, etc...) and add parameters to be passed to neobook, or just make direct call: ReturnNB('valueToNB').
Syntax:
Code: Select all
window.external.nbSetVar('HelloFromTheWebBrowser', valueToNB);


http://www.mediafire.com/?1m71mwd5drd4hx8

PostPosted: Fri Jan 20, 2012 11:28 am
by Neosoft Support
Sorry for the confusion, but you cannot use the square brackets around the variable name when calling nbSetVar or nbGetVar inside the BrowserExecScript action. The reason is that NeoBook will try to populate those variables before passing the JavaScript on to the browser to be executed. Since the [rawHTML] variable is empty when BrowserExecScript is executed the population of variables by NeoBook will convert the script from this:

window.external.nbSetVar( '[rawHTML]', TXTarea );

to this:

window.external.nbSetVar( '', TXTarea );

Which, as you've discovered, won't work. To resolve this problem, you can use just remove the square brackets [ ] from the script. For example, the following will work:

Code: Select all
BrowserExecScript "WebBrowser1" "var TXTarea=(tinyMCE.get('elm1').getContent());|window.external.nbSetVar( 'rawHTML', TXTarea );" "JScript"


The variable brackets can be used when nbSetVar is embedded inside the actual HTML document since NeoBook can't populate code that originates from the browser.

PostPosted: Fri Jan 20, 2012 12:17 pm
by dpayer
Neosoft Support wrote:Sorry for the confusion, but you cannot use the square brackets around the variable name when calling nbSetVar or nbGetVar inside the BrowserExecScript action.


Thanks! That was the issue.

David