C
C
colorkid2018-09-30 11:24:22
JavaScript
colorkid, 2018-09-30 11:24:22

How to embed iframe only 1 time?

I am making a chrome extension, creating a popup by creating an iframe in the content script (I need an iframe and not a default popup).
I am creating an iframe.
I put it in via document.body.appendChild(iframe).

Everything works ok, BUT for the time being, until you open the application on a site where there are a bunch of other advertising iframes... For example, on the site https://www.rbc.ru/ , my iframes are created several times inside each advertising iframe given site.

QUESTION:
How can I create my iframe only once and put it only in the "Parent body" of the site?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alfangur, 2018-09-30
@colorkid

when creating your iframe, you need to specify that window is the main iframe and not the secondary iframe. on a page with an iframe's you can determine if it is an iframe with the following code

if (window && window.top === window) {
  // основная страница окна
} else {
  // iframe

whether it works in extensions, check. the final decision will be close to that.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question