Page 1 of 1

BrowserExport

PostPosted: Tue May 31, 2016 2:34 am
by fkapnist
BrowserExport (copy the contents of a Web Browser object to a variable) will crash if browser contents are UTF-8. Google reported that in 2008, UTF-8 became the most common encoding for HTML files. UTF-8 is the dominant character encoding for the World Wide Web, accounting for 86.9% of all Web pages in May 2016.

:(

.

Re: BrowserExport

PostPosted: Tue May 31, 2016 12:10 pm
by fkapnist
The internal compiler of Neobook does not support Unicode text. If you want to get some meta data from a web page and don't know if it is in a foreign language, I made a "hidden control" that encodes and decodes UTF-8 foreign text on-the-fly.

Image

The object is named WebBrowserUTF8. In this case, it gets the title of a page in WebBrowser1 and encodes it as a plain numeric string. There are no commas, semi-colons or special characters. Only numbers, which can be stored as variables and saved to INI files and Neobook databases. It then sends the numeric string to TABB1 (a title display bar object) which decodes it back to HTML and shows the correct foreign text. It is automatic or on-the-fly if you include GoSub "ShowTitle" in the Navigate Complete Tab of WebBrowser1.

-------------------------------------

Here is the Neobook GoSub "ShowTitle" Action:

Syntax: [ Download ] [ Hide ]
Using Neobook Syntax Highlighting
:ShowTitle
BrowserExecScript "WebBrowserUTF8" "window.encryptform.objn1.value = 'WebBrowser1';" "JScript"
BrowserExecScript "WebBrowserUTF8" "window.encryptform.objn2.value = 'TABB1';" "JScript"
BrowserExecScript "WebBrowserUTF8" "window.encryptform.objn3.value = 'GoSub ShowTitle';" "JScript"
SetVar "[TempClipboard]" "[Clipboard]"
Delay "10"
BrowserExecScript "WebBrowser1" "var info=(window.document.title);|window.clipboardData.setData ([#34]Text[#34], info);" "JScript"
Delay "10"
BrowserExecScript "WebBrowserUTF8" "window.GetHTML();" "JScript"
Delay "10"
BrowserExecScript "WebBrowserUTF8" "window.SetHTML();" "JScript"
Delay "10"
SetVar "[Clipboard]" "[TempClipboard]"
Delay "10"
BrowserExecScript "TABB1" "window.SetHTML();" "JScript"
Return
Parsed in 0.008 seconds, using GeSHi 1.0.8.10



----------------------------------------


The WebBrowserUTF8 object is placed somewhere to the left, outside of the program master page window, so it cannot be seen by the user. Here is (nbUTF8.htm) the HTML code of WebBrowserUTF8:

Syntax: [ Download ] [ Hide ]
Using Javascript Syntax Highlighting
<html>
<head>
<META http-equiv="Content-Type" content="text/html;charset=UTF-8">
<SCRIPT LANGUAGE="JavaScript">
<!-- Original:  Mike McGrath (mike_mcgrath@lineone.net) -->
<!-- Web Site:  http://website.lineone.net/~mike_mcgrath/ -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://www.javascriptsource.com -->

<!-- Begin
var str_in;
var str_out = "";
var num_in;
var num_out = "";
// var e = "Enter Text!";
function str_to_num(form) {
num_out = "";
// if(form.input.value == "") alert(e);
if(form.input.value == "")  ;
else {
str_in = escape(form.input.value);
for(i = 0; i < str_in.length; i++) {
num_out += str_in.charCodeAt(i) - 23;
}
form.output.value = num_out;
form.input.value = "";
   }
};
function num_to_str(form) {
str_out = "";
// if(form.output.value == "") alert(e);
if(form.output.value == "")  ;
else {
num_out = form.output.value;  
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;
}
form.input.value = unescape(str_out);
form.output.value = "";
   }
};
//  End -->
</script>

<script language="JScript">
<!-- UTF-8 HTML:  FOT K KAPNISTOS -->
function nbInit() {
str_in=(window.clipboardData.getData ("Text"));
num_in=window.external.nbGetVar( '[UTFstr]' );
};
//  End -->
</script>
<script language="JScript">
function GetClip() {
info=(window.clipboardData.getData ("Text"));
document.encryptform.input.value =info;
};
</script>
<script language="JScript">
function SetClip() {
var info=document.encryptform.input.value;
window.clipboardData.setData ("Text", info);
};
</script>
<script language="JScript">
function GetHTML() {
GetClip();
str_to_num(encryptform);
SetVars();
 };
</script>
<script language="JScript">
function SetHTML() {
GetVars();
num_to_str(encryptform);
SetClip();
 };
</script>
<script language="JScript">
function GetVars() {
encryptform.output.value = window.external.nbGetVar( '[UTFstr]' );
};
</script>
<script language="JScript">
function SetVars() {
window.external.nbSetVar( '[UTFstr]', encryptform.output.value );
};
</script>
<script language="JScript">
function HideThis() {
window.external.nbExecAction( 'ObjectToBack "WebBrowserUTF8" ' );
window.external.nbExecAction( 'MoveObject "WebBrowserUTF8" "-673" "-617"' );
};
</script>
</head>

<body>
<center>
<form name="encryptform" name="encryptform">
<table>
<tr>
<td align=center><b><font face="Arial" size="2" color="#5C5C5C">UTF-8 HTML Text
  / nbNum String</font></b></td>
<td> </td>
<td align=center></td>
</tr>
<tr>
<td align=center><input type=button value="Get HTML & Set nbNum" onClick="GetHTML();"><input type=button value="Get nbNum & Set HTML " onClick="SetHTML();">
</td>  
<td> </td>  
<td align=center></td>  
</tr>  
<tr>  
<td align=center><input type=button value="object name" id="objn1" name="objn1" onClick="GetHTML();" style="font-family: Arial; font-size: 8pt; background-color: #FFFFFF; color: dodgerblue; border-style: inset; border-width: 1"><font face="Arial" size="1">
  &lt; Get from<font color="#FFFFFF">___</font>Send to &gt; </font><input type=button value="object name" id="objn2" name="objn2" onClick="SetHTML();" style="font-family: Arial; font-size: 8pt; background-color: #FFFFFF; color: dodgerblue; border-style: inset; border-width: 1"></td>    
<td> </td>    
<td align=center></td>    
</tr>    
<tr>    
<td align=center>    
  <font face="Arial" size="2">    
  HTML Text: </font><input type=button value="To nbNum String" onClick="javascript&#058;str_to_num(this.form)"><br>              
  <textarea rows="2" name="input" id="input" cols="20">Waiting...</textarea><br>              
  nb<font face="Arial" size="2">Num String: </font><input type=button value="To HTML Text" onClick="javascript&#058;num_to_str(this.form)">              
  <br>                
  <input name="output" id="output" type=text size=40><br>                
  <input type=button value="Get nbNum String" onClick="GetVars();"><input type=button value="Set nbNum String" onClick="SetVars();">  
  <br>
  <font face="Arial" size="1">Action =</font> <input type=button value="NB Action" id="objn3" name="objn3" style="font-family: Arial; font-size: 8pt; background-color: #FFFFFF; color: dodgerblue; border-style: inset; border-width: 1"><br>    
  <input type=button value="Hide This In/Out Control" onClick="HideThis();">                
</td>                  
<td align=center>                  
<br>                  
</td>                  
<td align=center></td>                  
</tr>                  
</table>                  
</form>                  
</center>                  
 </body>                  
</html>
Parsed in 0.025 seconds, using GeSHi 1.0.8.10


-------------------------------------------

The TABB1 object is used as a text bar to display web page titles somewhere in your program. Here is (theTitle.htm) the HTML code:

Syntax: [ Download ] [ Hide ]
Using Javascript Syntax Highlighting
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<META http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>The Title</title>
<SCRIPT LANGUAGE="JavaScript">
function SetHTML() {
var nbNum= window.external.nbGetVar( '[UTFstr]' );
str_out = "";
if(nbNum == "")  ;
else {
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);
document.getElementById('B3').value=info;
   }
};
</script>
<script>
function jumptop() {
window.location.hash="";
};
</script>
</head>
<body topmargin="0" leftmargin="0" onmouseup="jumptop();" ondrag="jumptop();" ondragstart="jumptop();" ondragend="jumptop();">
<input type="button" value="My Browser " id="B3" name="B3" onmouseup="jumptop();" ondrag="jumptop();" ondragstart="jumptop();" ondragend="jumptop();" style="background-color: #FFFFFF; color: #808080; font-family: Arial Narrow; font-size: 10pt; font-weight: bold; border: 0 solid #FFFFFF">
</body>  
</html>
Parsed in 0.008 seconds, using GeSHi 1.0.8.10


---------------------------------------------------------------

This hidden control uses the clipboard only once - with Javascript to store a foreign page title. TABB1 however does not get the title from the clipboard, but from the Neobook number string [UTFstr] and decodes it back to foreign text on-the-fly. I am now working on a solution that will require no clipboard use.

:P

.

Re: BrowserExport

PostPosted: Tue May 31, 2016 6:01 pm
by Neosoft Support
I wasn't able to get BrowserExport to crash, but the with UTF8 text doesn't come out correctly (as expected) in the variable.