I need to place an advertisement as a background image of my webpage. What's the best way to make the body background image a clickable link开发者_运维百科?
You can't make a background image clickable. Is your image taking the whole body space ?
Or you can you use javascript:
$("body").click(function(event){
event.stopPropagation();
alert('oh hai');
});
This is how I make the body background-image clickable:
$('body').css({'background': 'url(yourimage.jpg) top center no-repeat'})
$('body').click(function(e){
if (e.target === this) {
window.open('http://link.html', '_blank');
}
});
You can also use window.location instead of window.open(). Hope this helps.
精彩评论