What I’m trying to do:
I Have an iframe which starts on an index.html file and then transitions to a goodbye.html file when the content has been finished.
i need to add an onload function callback to the iframe.
What I’ve tried and what’s not working:
I’ve tried to add an attribute to the iframe, as shown in the code snippet, however this yields the expected result of “ReferenceError: iframe_loaded is not defined”, how can I add my function to the page before trying to load the iframe?
Code Sample:
iframe = None
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# Create an iframe element and set the src
self.iframe = jQuery("<iframe width='100%' height='800px'>").attr("src","url").attr("onload", "iframe_loaded()")
self.iframe.appendTo(get_dom_node(self.content_panel))
def iframe_loaded(self):
# Check if the iframe source ends with goodbye.html
if self.iframe != None:
if self.iframe.attr('src').endswith('goodbye.html'):
# Run your code here
print("Transition to goodbye.html")``
Just a note, that the url provided is not actually “url” as the snippet shows.