开发者

css body background image clickable

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜