开发者

css body background image clickable

开发者 https://www.devze.com 2023-01-09 03:23 出处:网络
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 clickabl

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

精彩评论

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

关注公众号