Controlling inner HTML / HTML widget

I have an HTML widget containing an iframe for a video. If, while the video is playing, the user clicks on another button, I would like the video to stop playing. I have used this:

var emptyInnerHTML = ''; 

hypeDocument.getElementById(“Video”).innerHTML = emptyInnerHTML

This effectively empties the widget and stops it playing. However, how can I reload the innerHTML with the iframe once again?

Thanks!

You would use the iframe src code and just load it right back in. Note that I use " inside of the JavaScript string, but ' to encapsulate it.

var newinnerContent = '<iframe src ="https://www.youtube.com/embed/#####" width="400px" height="400px" scrolling="no" style="border:none;"></iframe>';

document.getElementById("Video").innerHTML = newinnerContent
1 Like

works perfectly. Thanks!

1 Like

Thank you very much for your contribution, it was very helpful. regards

Hi @Daniel!
The code snippet you provided above a while back works well and we use it all the time for restarting videos within iFrames (by emptying and adding content back in). But when I tried using it to reload with results from a polling form, it doesn't work.... Not sure what I'm doing incorrectly?
RealtimeResults.zip (44.0 KB)

It looks like you're trying to write a JavaScript function to be placed inside of an iframe on click, but this isn't something you can do. :blowfish:!

Does Wufoo not provide a regular URL for results? That would be ideal in this situation. Then you can set an HTML widget.

Alternatively, you can create a regular HTML page containing that wufoo code and upload it to your server. And you can use that HTML page as your source for an HTML widget.

If you want to reload an HTML widget, you can set a Unique Element ID for that HTML widget (something like myframe1). Make sure you're setting this on the HTML widget and not a group it is contained in.

Then run this function to reload it:

var myframe1element = hypeDocument.getElementById("myframe1").getElementsByTagName("iframe")[0]; 

// get the source of the current frame and reload it: 
myframe1element.src = myframe1element.src
1 Like

Thanks @Daniel. Wufoo doesn't provide a URL for results - has to be the embed code but I took your idea of putting the results in another HTML page and then creating an iframe to that which refreshes on button click. Works well now!

1 Like