Jump to content

Javascript to control AdSense

- - - - -

  • Please log in to reply
5 replies to this topic

#1
king4aol

king4aol

    Newbie

  • Members
  • Pip
  • 1 posts
How do I make a script that close my ad (google adsense) after an interval of 15 sec automatically.

#2
haltox

haltox

    Newbie

  • Members
  • PipPip
  • 29 posts
You could create a function to set the display property of the div containing the ad to none. Then use the fonction setTimeout() with a 15 seconds delay to call the previously defined function in the body onLoad event.

#3
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
Setting display to none:
<div id="some_div">...</div> 

<script type="text/javascript"> 

document.getElementById("some_div").style.display= "none"; 

</script> 
(You can use this:
document.getElementById("some_div").style.display= "inline"; 
to set the display back to normal.)

Using the setTimeout() function:
<script type="text/javascript"> 

setTimeout("some_code_to_execute();", 15000); 


function some_code_to_execute(){ 

  // do something...  

} 

Though, as far as I understand, you don't have to put it into the <body onLoad=...> event, do you?
I mean, I have been just using the <script type="text/javascript"> tag somewhere within the <head> or <body> element and those scripts were executed when the page was loaded.
(I mean, :
<html> <head> <title> the title </title> </head> <body> <h1> some page </h1> <div id="hello"> </div> <script type="text/javascript"> document.getElementById("hello").innerHTML= "<span style=\"font-weight: bold;\"> Hello World! </span> <BR> "; </script> </body> </html> 
that JavaScript code should execute when the page is loaded.)

#4
haltox

haltox

    Newbie

  • Members
  • PipPip
  • 29 posts
It's usually better practice to put it in the onLoad event since the div element could not be loaded when the script execute. However, with a 15 seconds delay this should'nt be a problem.

#5
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
Maybe put the <script> after the <div>?

#6
haltox

haltox

    Newbie

  • Members
  • PipPip
  • 29 posts
That would work and is often encouraged since the browser will usually stop to load the script and then continue loading the page, which results in slowing the rendering of the page. With the script at the end, the user will only have to wait for the advanced functionality, which is usually not dramatic. There are also some people who load the script asynchronously to increase performance in some ways.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users