You need to get links from banners on the site via JavaScript in Chrome browser. Sample page where banners are placed

As an example, I took the site speedtest.net, where the banners are located: as seen in the screenshot - Chrome can see the banner links, but how to achieve this yourself using JavaScript?

  • one
    Please try to write correctly: - not strong, - by means, - the comma is placed close to the previous word and after it is a space. Specify the essence of the question: do you want to get a link on the page of your site or do you need some bookmarklet to process an arbitrary page? - artoodetoo

3 answers 3

If I understand you correctly - you should use a special extension for Chrome: Tampermonkey . This extension allows you to run your scripts on the necessary pages / domains, etc.

As for the script itself:

If you use pure JS:

// Сохраняем в переменную узел с нашим баннером, узнав его по id var someDOMElement = document.getElementById('aw0'); // А так мы можем взять любой атрибут, например href var hrefOfelement = someDOMElement.getAttribute('href'); // Можно всё делать в одну строку var hrefOfelement = document.getElementById('aw0').getAttribute('href'); 

Elements can be obtained by other attributes.

As for your task, the algorithm is as follows: 1) Collect all the elements you need for DOM, for example, into an array (in JS these are objects); 2) In the cycle we go through each of them.

    From the page to get to the elements inside the ifram of another domain is impossible, unless chrome is running with the --disable-web-security flag.

      Banner advertising is usually created on the basis of frames, where a frame on the page of your site opens a page on another domain (domain of the advertising platform).

      Because of the security policy of the browser, it is impossible to get the contents of a frame located on another domain.