How do I make a script that close my ad (google adsense) after an interval of 15 sec automatically.
5 replies to this topic
#1
Posted 24 July 2011 - 01:30 AM
|
|
|
#2
Posted 08 August 2011 - 05:21 AM
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
Posted 08 August 2011 - 06:05 PM
Setting display to none:
Using the setTimeout() function:
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, :
<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
Posted 09 August 2011 - 06:23 AM
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
Posted 09 August 2011 - 11:40 AM
Maybe put the <script> after the <div>?
#6
Posted 09 August 2011 - 12:19 PM
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


Sign In
Create Account

Back to top









