HTML Local Storage Objects

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Locked
User avatar
fkapnist
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece
Contact:

HTML Local Storage Objects

Post by fkapnist »

HTML local storage provides objects for storing data on the client. "window.localStorage" stores data with no expiration date.

You can Store text in one browser window:
window.localStorage.setItem("lastname", "Smith");

And Retrieve in another browser window:
window.document.getElementById("result").innerHTML = window.localStorage.getItem("lastname");

I want to use this method instead of cookies or clipboard data. But it will not work for me. Am I doing something wrong or is "window.localStorage" not supported in WebBrowser objects?

Thanks in advance

.
Neosoft Support
NeoSoft Team
Posts: 5628
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA
Contact:

Re: HTML Local Storage Objects

Post by Neosoft Support »

Local storage is stored under the website address isn't it? So can this even be used with local content (which sounds like what you're trying to do with NeoBook)?
NeoSoft Support
User avatar
fkapnist
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece
Contact:

Re: HTML Local Storage Objects

Post by fkapnist »

Neosoft Support wrote:Local storage is stored under the website address isn't it? So can this even be used with local content (which sounds like what you're trying to do with NeoBook)?

What I am trying to do is this:

To get a page title with javascript (window.document.title) and set it as a text field value in a form of another WebBrowser object. Because it is a foreign text title I cannot use the standard Neobook actions. The only method that works for me is window.clipboardData.setData ("Text", info);. But I don't want to mess with the user's clipboard for security reasons. Can it be done with VB or something else?

:?:

.
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: HTML Local Storage Objects

Post by Gaev »

fkapnist:
Can it be done with VB or something else?
This page ... https://mothereff.in/utf-8 ... contains a tool for encoding/decoding UTF-8 strings ... it also points to this GitHub page ... https://github.com/mathiasbynens/utf8.js ... which contains the utf8.js source used in the tool.

Perhaps you can pass encoded text from one BrowserObject to a NeoBook variable ... then pass the NeoBook variable content to the other BrowserObject and decode it over there.
User avatar
fkapnist
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece
Contact:

Re: HTML Local Storage Objects

Post by fkapnist »

Gaev wrote:fkapnist:
Can it be done with VB or something else?
This page ... https://mothereff.in/utf-8 ... contains a tool for encoding/decoding UTF-8 strings ... it also points to this GitHub page ... https://github.com/mathiasbynens/utf8.js ... which contains the utf8.js source used in the tool.

Perhaps you can pass encoded text from one BrowserObject to a NeoBook variable ... then pass the NeoBook variable content to the other BrowserObject and decode it over there.
That is exactly what I am trying to do... but how do I encode text in a WebBrowser object in the first place without using a Neobook action? I can't bring it into Neobook before it is encoded because Neobook doesn't support Unicode and may hang trying to read foreign language characters (??? ?? ?). If I use Javascript I can't save it as a file or pass it to other WebBrowser objects due to Javascript limitations (JS only works within its own WebBrowser object window) ... That's why I was thinking about VBscript or Pascal... I think they can encode text and save results to file, after which Neobook can then open and read as a numeric code... It is funny that the clipboard can easily do it transparently but nothing else seems to work for now...


I am stuck trying to pass a Javascript variable between two WebBrowser objects and I can't use Neobook actions for that.... If they were two pages in the same WebBrowser object, I could pass variables by appending them to the url from one page to another. But I have pages contained within different WebBrowser objects and Javascript cannot communicate without using Neobook actions, which will chew up the foreign language characters before they get encoded...
User avatar
fkapnist
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece
Contact:

Re: HTML Local Storage Objects

Post by fkapnist »

Let me recap what I am trying to do:

I want to get the title of a page and display it in a text field. Rather easy it seems, except I don't know in advance if the title is in English or a foreign language. Let's assume it is a foreign language, so it will have to be encoded. Javascript can do that, but then what? The text field is in a different WebBrowser object and it is impossible for Javascript to access that object or save the title as a file.

:oops:

.
User avatar
Gaev
Posts: 3782
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada
Contact:

Re: HTML Local Storage Objects

Post by Gaev »

fkapnist:
Let's assume it is a foreign language, so it will have to be encoded. Javascript can do that, but then what? The text field is in a different WebBrowser object and it is impossible for Javascript to access that object or save the title as a file.
When you want to perform this task ...

1) Invoke a BrowserExecScript on the first WebBrowser object

2) The passed (javascript) commands would do the encoding ... and then pass the encoded value back to a (NeoBook) variable ... finally, the (javascript) command (nbExecAction) would be used to trigger a NeoBook subroutine ... something like ...

Code: Select all

window.external.nbExecAction( 'GoSub "DoTheDecode"' );
3) This NeoBook soubroutine would invoke another BrowserExecScript on the second WebBrowser object

4) The passed (javascript) commands would do the decoding ... and populating of the Text Field


You can do a simple "proof of concept" by doing a simple pass of the English (ascii) titles (or any other simple text) ... once that is proven, you can work on the more complex task of passing the afore mentioned encode/decode javascript commands.
User avatar
fkapnist
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece
Contact:

Re: HTML Local Storage Objects

Post by fkapnist »

Gaev wrote:once that is proven, you can work on the more complex task of passing the afore mentioned encode/decode javascript commands.
Thanks for the help! I did finally solve it, but there was a problem with "undocumented" syntax rules...

According to the Neobook Help file, this is the correct syntax:
window.external.nbSetVar( '[UTFstr]', info );

However, when used in the BrowserExecScript JScript Editor, this is what actually worked:
window.external.nbSetVar( 'UTFstr', info );

The brackets were not needed at all.

.
User avatar
fkapnist
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece
Contact:

Re: HTML Local Storage Objects

Post by fkapnist »

Here is the final version (based on encoder by Mike McGrath)...

The WebBrowser object of the web page:
[syntax=neobook]BrowserExecScript "WebBrowser1" "var info=(window.document.title);|num_out = [#34][#34];|str_in = escape(info);|for(i = 0; i < str_in.length; i++) {num_out += str_in.charCodeAt(i) - 23;}|codedinfo = num_out;|window.external.nbSetVar('UTFstr',codedinfo);" "JScript"[/syntax]

The WebBrowser object of the title text field:
[syntax=neobook]BrowserExecScript "WebBrowserUTF8" "var nbNum= window.external.nbGetVar( 'UTFstr' );|str_out = [#34][#34];|num_out = nbNum;|for(i = 0; i < num_out.length; i += 2) {num_in = parseInt(num_out.substr(i,[2])) + 23;|num_in = unescape('%' + num_in.toString(16));|str_out += num_in;}|var info= unescape(str_out);|window.document.getElementById('B3').value=info;" "JScript"[/syntax]

Amazing! Notice how tiny this code is compared to the ... https://mothereff.in/utf-8 ... and other "oversized" tools for encoding/decoding UTF-8 strings. And no interference with the user's clipboard.

:lol:

.
Locked