Python Forum
Return string from Javascript - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Return string from Javascript (/thread-8241.html)



Return string from Javascript - ian - Feb-11-2018

I need to get a string returned from JavaScript but cannot find a good way. Like in the code below, is there a way to get content of 'substring' in Java returned to python code so I can print() it? Thanks.

import wx
import wx.html2 as Browser

class Frame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title="Youtube Downloader", size=(1450, 750), pos = (0, 0))
        wx.Panel(self)
        self.SetBackgroundColour(wx.Colour(248,248,248))
        self.URL = 'https://www.google.com'
        self.wv = Browser.WebView.New(self, url=self.URL, pos=(0, 35), size=(1450,750))
        self.Bind(Browser.EVT_WEBVIEW_LOADED, self.On_Load, self.wv)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.wv)
        self.SetSizer(sizer)
        self.wv.LoadURL(self.URL)
    def On_Load(self, event):
        self.wv.RunScript("""
            substring = 'Hello World!'.substr(0,5);
            alert(substring);
        """)
        print('substring')
if __name__ == "__main__":
    app = wx.App()
    win = Frame()
    win.Show()
    app.MainLoop()