Hey everyone I made a ui application that opens uses a custom view with a webview with a few other textviews ,buttons, and etc to run js on the webpage presented on the webview and display the results on a textview.
In the docs it doesn’t explain how the js should be structured in order to get the results from the snippets used. So I was wondering if anyone can tell me how to correctly use the method?
I’m gonna include code from my application (excluding animation functions I use for each separate view) and I’ll wait for responses. I appreciate any help I can get, and thanks in advance!!!
class browser(ui.View):
def did_load(self):
self.html = 0
html_view = ui.load_view('html_view')
self.add_subview(html_view)
self['html_view'].x = 400
def go(self):
v = self.superview
url_bar = v['url input']
webview = v['webview1']
webview.load_url('http://'+url_bar.text)
# this is located on a custom view that
#is a subview to the view containing the webview
class html_view(ui.View):
#this is a button located on the subview
#that initiates the "webview.evaluate_javascript()" method
def runjs(self):
#this is the subview
v = self.superview
#this is the main view
bv = v.superview
#the textview that the script is entered in
script = v['js field'].text
#the variable that contains the result of
#the method
result = bv['webview1'].evaluate_javascript(script)
#Printing result for testing purposes
print(result)
#setting a textview to the result''
v['result'].text = result