HTML Local Storage Objects
Moderator: Neosoft Support
HTML Local Storage Objects
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
.
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 Team
- Posts: 5628
- Joined: Thu Mar 31, 2005 10:48 pm
- Location: Oregon, USA
- Contact:
Re: HTML Local Storage Objects
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
Re: HTML Local Storage Objects
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?
.
Re: HTML Local Storage Objects
fkapnist:
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.
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.Can it be done with VB or something else?
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.
Re: HTML Local Storage Objects
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...Gaev wrote:fkapnist:
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.Can it be done with VB or something else?
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.
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...
Re: HTML Local Storage Objects
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.
.
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.
.
Re: HTML Local Storage Objects
fkapnist:
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 ...
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.
When you want to perform this task ...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.
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"' );
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.
Re: HTML Local Storage Objects
Thanks for the help! I did finally solve it, but there was a problem with "undocumented" syntax rules...Gaev wrote:once that is proven, you can work on the more complex task of passing the afore mentioned encode/decode javascript commands.
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.
.
Re: HTML Local Storage Objects
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.
.
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.
.