[Gambas-user] Copying large string from javascript procedure

Safiur Rahman isafiur at gmail.com
Wed Jul 20 17:57:46 CEST 2022


Hi

Is there a way to copy large string from javascript function (in
gb.web.gui) so that it can be used elsewhere.

Currently only few controls (eg. WebTextBox) can be filled from
javascript procedure. However, WebTextBox is not able to hold large
data (eg. from image).

Case:1 (works fine)

Public Sub WebButton5_Click()

  WebForm._AddJavascript("var xdata = 'abcdef'")
  WebForm._AddJavascript("$_(" & JS(WebTextBox1.Name & ":entry") &
").value = xdata")
  WebForm._AddJavascript("gw.update(" & JS(WebTextBox1.Name) & ",
'text', xdata);")

End
-> string shown in WebTextBox


Public Sub WebButton4_Click()

  WebHtml1.Html = WebTextBox1.Text

End
-> "abcdef" is displayed in WebHtml



Case:2 (doesn't work fine)

Public Sub _new()

  Me.AddJavascriptFile("js/sketchpad.js")
  ''https://github.com/tsand/responsive-sketchpad

End

Public Sub WebContainer1_Render()

  WebForm._AddJavascript("var pad = new Sketchpad($_(" &
JS(WebContainer1.Name) & "), { line: {color: '#f44335', size: 1}});")

End


-> Now I draw on the screen


Public Sub WebButton1_Click()

  WebForm._AddJavascript("var xdata = pad.canvas.toDataURL(\"image/png\")")
  WebForm._AddJavascript("$_(" & JS(WebTextBox1.Name & ":entry") &
").value = xdata")
  WebForm._AddJavascript("gw.update(" & JS(WebTextBox1.Name) & ",
'text', xdata);")

End
-> Image data string shown in WebTextBox


Public Sub WebButton4_Click()

  WebHtml1.Html = WebTextBox1.Text

End
-> image data string is not shown in WebHtml

Question: Is there any way to show the image data string to any
WebControl which can be copied and used elsewhere in other procedures?

(Attached a project to reproduce the problem. Please rename
js/sketchpad.txt to js/sketchpad.js)

-- 
Regards
Safiur Rahman


More information about the User mailing list