I have looked on many websites but none of them seem to work right or I don't understand them. I would like a simple button that refreshes a certain iframe. The button would be on the parent page and the iframe name is "Right".
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
There are many ways to do this. Assuming this
iframe
markup:We can do it with a function call:
HTML
JS
Or with inline JS:
Or using an event listener:
HTML
JS
Same as above, now with support for IE <= 8 and using a function in the global scope as handler instead of an anonymous one:
HTML
JS
All of this without even touching jQuery or any other library.
Which of these you should use? Whichever you consider more maintainable and readable. Just avoid global vars whenever possible. I'd personally avoid inline JS with the markup, and the listeners seem to be unnecessary, but that's just me. Choose whichever suits you better.
Add new
id
in your iframe and try below code.