Jump to content


Photo

Html Background Click ?


  • Please log in to reply
3 replies to this topic

#1 Manixat

Manixat

    Advanced Member

  • Members
  • PipPipPip
  • 166 posts

Posted 17 December 2012 - 04:37 AM

Hey, I want to place an advertisement on my pages' HTML tag BACKGROUND-IMAGE, but the problem is I can't figure out how to detect a click ?

#2 SocialCloud

SocialCloud

    Advanced Member

  • Members
  • PipPipPip
  • 613 posts

Posted 17 December 2012 - 08:46 AM

You can wrap it in a div or class then use a jquery call:

$("#div").click(function()
// or$(".class").click(function() {
{

do something

});


#3 Manixat

Manixat

    Advanced Member

  • Members
  • PipPipPip
  • 166 posts

Posted 17 December 2012 - 09:04 AM

yeah that's obvious but that would be the solution if there's no way of detecting a click on the html element where there's nothing above it ( in the 3D schema )

#4 Petermichael703

Petermichael703

    Member

  • Members
  • PipPip
  • 21 posts

Posted 13 December 2013 - 01:15 PM

hi .manixat

To accomplish this, you may get solutions like adding <a> around <div>. But it won’t be a good practice as per standard. Finally you may end up with replacing <div> with <IMG>.  But you will never get the desired output.

But my solution is quite simple. Make it clickable with JavaScript.

Simple Jquery Solution is

 

$(document).ready(function() {

$("div.js-ad-home-page-background").click(function(event){

window.open('LINK_TO_ADVERTISE');

});

});

Common Issues

Ad links will won’t work if there is no JavaScript(which is not at all happen now days) and if any JS error in page. Which are common. So make sure that no script error before this jQuery snippet

Note:

Make sure that you have added jquery.js

let me know if it helps






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com