Last active
January 15, 2024 06:25
-
-
Save sureshHARDIYA/c662dc6b3d66fca58d83fbbd4c8137f3 to your computer and use it in GitHub Desktop.
Create Google Adsense ad using JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var adUnit = document.getElementsByClassName("section-below-title")[0]; | |
var parentElement = adUnit.childNodes[0]; | |
// Create script element | |
var script = document.createElement('script'); | |
script.async = true; | |
script.src = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"; | |
parentElement.appendChild(script); | |
// Create INS element | |
var ins = document.createElement('ins'); | |
ins.className = "adsbygoogle"; | |
ins.style = "display:inline-block;width:300px;height:250px;"; | |
ins.setAttribute('data-ad-client', "ca-pub-XXXXXXXXXXXXXXXX"); | |
ins.setAttribute('data-ad-slot', "XXXXXXXXXX"); | |
parentElement.appendChild(ins); | |
(adsbygoogle = window.adsbygoogle || []).push({}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment