M
M
mxbeat2016-10-06 10:15:22
JavaScript
mxbeat, 2016-10-06 10:15:22

How to display different ad units on mobile and PC?

Can you tell me the code that can be used to display different ad units for mobile and PC users? For example, to display a Yandex ad block for PC users, and Google ads for mobile users. The option to hide one of the blocks in css via media queries is not suitable.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sergski, 2016-10-06
@sergski

var userAgent = window.navigator.userAgent;
if (/Windows|Mac/.test(userAgent)) {
    // код для пк
} else if (/Android|iPad|iPhone|iPod/.test(userAgent)) {
    // код для моб, апл или андроид
} else {
    // код под другие ос
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question