How to replace iframe using the JavaScript

The task replace content of iframe after click on button inside Iframe.

It doesn’t easy task because we can’t change «src» attribute. It will be security issue if child iframe refers to other domain.

In common case for resolve this issue you should to delete old iframe from parent document and create new iframe. But for this you should have access to parent page.

Let’s have look at an example:

index.html (parent page contains iFrame)



Using this example you can replace iframe linked on other domain.

In Additional:

I also noticed that iframe difficult to hide. For exsample if you add style visibility: hidden; Internet Explorer may stop responding.
Style display: none; can cause problems with a page layout.

Ваши комментарии к статье:


Оставить комментарий

Ваш адрес email не будет опубликован.

Этот сайт использует Akismet для борьбы со спамом. Узнайте, как обрабатываются ваши данные комментариев.