javascript - Refreshing iframe error -


i using iframe in div block , trying change src through button click following code.

function helloclick(){             var iframe = document.getelementbyid("iframediv");             iframe.src = "hello_world";             iframe.contentdocument.location.reload(true); } 

the hello_world file located in same folder file iframe defined. following error message every time click on button.

uncaught typeerror: cannot read property 'location' of undefined 

how resolve issue?

try below code snippet

function helloclick(){             var iframe = document.getelementbyid("iframediv");             iframe.src = "hello_world";             iframe.src = iframe.src; } 

it should you.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -