Updating a webview
I'm fairly new to Pythonista development and was struggling to get the contents of a webview to change when I click a button in my script.
The script has a UI, on which I've dropped a button and a webview. I've wired the button event to 'ButtonClick' (below), and I know this gets called as I've tested it with a console alert. I've tried alternatives such as referring to the original webview instance and also via the sender superview.
What I'm seeing is that the webview gets updated initially, but never seems to show the effect of the new contents in the button click ('my second heading'). What am I doing wrong?
import ui import tempfile import os import console def ButtonClick(sender): v1 = sender.superview #w=v1['webview1'] #console.alert(str(w)) w.load_html('<!DOCTYPE html><html><body><h1>My Second Heading</h1></html>') #w.present() v = ui.load_view('Test') w=v['webview1'] w.load_html('<!DOCTYPE html><html><body><h1>My First Heading</h1></html>') v.present('fullscreen')
Your code works exactly as expected for me. "My First Heading" is displayed initially in the WebView. After a button press, "My Second Heading" is displayed in the WebView.
@ccc Thanks ccc. A bit embarrassing but I'd left in the console alert on my script and that seems to prevent the webview from updating even after you acknowledge the alert. Without it, it works for me too.