Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Hiding DIV with Adsense Script
Old 04-30-2009, 12:11 AM Hiding DIV with Adsense Script
Average Talker

Posts: 21
Trades: 0
I was able to show or hide a DIV using javascript. However, after adding Adsense code within that DIV, I cannot hide the DIV anymore. Any idea how I can show it? many thanks
__________________
Gamer12


Please login or register to view this content. Registration is FREE
Gamer12 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-30-2009, 12:40 AM Re: Hiding DIV with Adsense Script
stevej's Avatar
Professional Multitasker

Posts: 996
Location: Not positive
Trades: 0
Why do you want to give the user the option to hide the ads?

And, while you're at it, some code would be pretty helpful as well.

- Steve
__________________
if($stevej == "helpful") { $talkupation += $user_power; }
stevej is offline
Reply With Quote
View Public Profile
 
Old 04-30-2009, 02:18 AM Re: Hiding DIV with Adsense Script
Average Talker

Posts: 21
Trades: 0
Hi Steve,

I want to protect my adsense from being bomb. So want to disable it if I have detected a certain IP has clicked on it for several time. However, for some reasons, I just not able to hide my DIV after pasting the Adsense code in it. Do you know how I can do it?

Quote:
Originally Posted by stevej View Post
Why do you want to give the user the option to hide the ads?

And, while you're at it, some code would be pretty helpful as well.

- Steve
__________________
Gamer12


Please login or register to view this content. Registration is FREE
Gamer12 is offline
Reply With Quote
View Public Profile
 
Old 04-30-2009, 10:07 AM Re: Hiding DIV with Adsense Script
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
What happens when you do this?
HTML Code:
<div style="display: none">
<!--adsense code here-->
</div>
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 04-30-2009, 12:27 PM Re: Hiding DIV with Adsense Script
stevej's Avatar
Professional Multitasker

Posts: 996
Location: Not positive
Trades: 0
Quote:
Originally Posted by Gamer12 View Post
However, for some reasons, I just not able to hide my DIV after pasting the Adsense code in it. Do you know how I can do it?
Well, I don't know HOW to do it, though I think wayfarer07's solution should work.

- Steve
__________________
if($stevej == "helpful") { $talkupation += $user_power; }
stevej is offline
Reply With Quote
View Public Profile
 
Old 04-30-2009, 01:13 PM Re: Hiding DIV with Adsense Script
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Ok, I tested this out on one of my pages which has an Adsense ad: http://wayfarerweb.com/tooltip-examples.php

Click on the link with a white, dashed line around it on the right, which reads "hide advertisement". When you click on this link, it adds a style of "display: none" to the <p> which wraps the link-unit. As you can plainly see, this hides the advertisement.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 04-30-2009, 09:31 PM Re: Hiding DIV with Adsense Script
Average Talker

Posts: 21
Trades: 0
Cool! WayFarer!!

How do you do that? I see this in the source for the "Hide Advertisement" link
<a id="hide-ad" href="#">Hide Advertisement</a>Cannot trace which js function is being called to add the "display:none"?

Many thanks

Quote:
Originally Posted by wayfarer07 View Post
Ok, I tested this out on one of my pages which has an Adsense ad: http://wayfarerweb.com/tooltip-examples.php

Click on the link with a white, dashed line around it on the right, which reads "hide advertisement". When you click on this link, it adds a style of "display: none" to the <p> which wraps the link-unit. As you can plainly see, this hides the advertisement.
__________________
Gamer12


Please login or register to view this content. Registration is FREE
Gamer12 is offline
Reply With Quote
View Public Profile
 
Old 04-30-2009, 09:52 PM Re: Hiding DIV with Adsense Script
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
all DOM objects have a style object. Every style object has properties which represent CSS styles. Styles with dashes in them must be expressed in camelCase, because JavaScript does not allow dashes in property names (a dash would indicate subtraction).

Any time you have a DOM object, you could change its display like this:
Code:
domObject.style.display = "none";
The most common way to create a DOM object is with document.getElementById. The above example could become:
Code:
var domObject = document.getElementById("my-elements-id");
domObject.style.display = "none";
now, the variable domObject is a reference to the HTML element with an id="my-elements-id", and can be manipulated.

The way I did it in my example will not help you. If you're interested in seeing the code, it may be found here, among other things: http://wayfarerweb.com/js/common.js

See the line which reads:
Code:
$("#hide-ad").click(function() {$("#link-unit, p:has(#hide-ad)").hide(); return false;})
What you're looking at is jQuery code, which relies on the popular library. It is basically a quicker way of selecting and manipulating things.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 05-08-2009, 02:59 AM Re: Hiding DIV with Adsense Script
Average Talker

Posts: 19
Trades: 0
Hi,
You're not altering the ad code in any way (which would be a violation),
the script will only replace the code if it is not functional anyway (i.e. the ad is not visible), it's not important how the ad was filtered. If the ad script cannot be executed because it simply cannot be loaded (by an entry in the HOSTS file) or if only the images are made invisible: The Ad script only kicks in if the ad could not be presented to the viewer. It's even possible to have the original ads replaced by locally hosted banners. This is useful to preserve the website design in case your visitor uses an AdBlock and you are using ads as design elements.
The DIV container:<div id="adsense"><script type="text/javascript">AdSense code goes here</script><noscript>Message displayed when JavaScript is disabled</noscript>
</div>
__________________

Please login or register to view this content. Registration is FREE
Hallbjörn Ólaf is offline
Reply With Quote
View Public Profile
 
Old 05-08-2009, 03:20 AM Re: Hiding DIV with Adsense Script
Banned

Latest Blog Post:
Oscar: The Bionic Cat
Posts: 237
Trades: 0
that's a good idea.. one way to avoid invalid clicks.. but make sure google allow it, to also avoid getting ban..
bogs is offline
Reply With Quote
View Public Profile Visit bogs's homepage!
 
Old 05-08-2009, 09:47 AM Re: Hiding DIV with Adsense Script
Average Talker

Posts: 20
Name: Nazia Naaz
Location: Karachi
Trades: 0
COOL thanks Way! it help my problem
__________________

Please login or register to view this content. Registration is FREE
iamboredr is offline
Reply With Quote
View Public Profile Visit iamboredr's homepage!
 
Reply     « Reply to Hiding DIV with Adsense Script
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.93519 seconds with 12 queries