I'm optimizing a site so that on a mobile browser it only shows the mobile adsense ad, and on desktop it only shows the regular one. Problem is the google code leaves a white space where these ads are on 开发者_JS百科the page.
I want to know if there is an easy way to programmatically insert the ad (JS) based on the user agent.
Thanks.
It's very simple, see Masquerading Your Browser for details on how the User-Agent header works. See also the HTTP specification.
You haven't said which server side language you're using. In PHP you would look at the value of $_SERVER['HTTP_USER_AGENT']
.
精彩评论