-17

I have a 300px x 250px ad which is in this form:

<script type="text/javascript" src="advert.com" ></script>

I want to create a button underneath the ad which says: "Close ad to continue as free user".

And once this button is clicked, the ad opens the example.com page on a new tab, and the ad disappears with the button

Does anyone know how I can do this?

zigg75483
  • 45
  • 6

2 Answers2

1

get the id or class of your ad with var ad = document.querySelector("adId or adClass")

get the id or class of your button that wil go underneath your add with var button = document.querySelector("buttonId or buttonClass")

then add a click event on the button with
button.addEventListener("click", function(e){ ad.remove()})

eltongonc
  • 97
  • 9
-1

Please use search in Stack Overflow before you ask a question. Look at this link:

Javascript - Open Link in New Tab (SAME WINDOW)

Also you might like to read this:

Javascript - Open a given URL in a new tab by clicking a button

But it is bad practice to use this because if you put to many adverts on the site user could never return to your site. Popups make users angry.

EDIT:

We need to know more about your script. You could set the display css property on the div element to none; or visibility to hidden. to do this in pure javascript you should use something like that:

document.getElementById(id).style.property=new style 

Here's a good description.

Community
  • 1
  • 1
  • 3
    to close add you should tell us more about your script. It could be set css property on the div element like display: none; or visibility: hidden; to do this in pure javascript you should use something like that: document.getElementById(id).style.property=new style The best description you have there: http://www.w3schools.com/js/js_htmldom_css.asp – Kacper Mironiuk Jan 21 '15 at 00:03