-1

while making a website that is only for desktop, and while viewing it on mobile I want an alert from browser to show that "not viewable in mobile!" I have tried the following-

script {
    display: none;
    pointer-events: none;
}

but these didn't work even tried by putting class and script inside a div and then giving class and more. always the alert is showing at desktop view also!! is there anyway possible?

6
  • 5
    I do not think CSS can affect JS being run. Try using matchMedia instead, as it's like using a media query in JS. Commented Dec 9, 2021 at 15:42
  • Just use Detecting a mobile browser, and if it is a mobile browser, don't execute the rest of the code Commented Dec 9, 2021 at 15:44
  • That will not work. Commented Dec 9, 2021 at 15:44
  • 2
    A <script> is already display: none; by default. There is no CSS property that affects <script> execution. That use case seems strange anyway. You mention media queries, so why not create a responsive design that works for both mobile and desktop? What is the difficulty with mobile? Seems like an XY problem. Commented Dec 9, 2021 at 15:46
  • 1
    How are you defining 'mobile' - viewport dimensions or some other capability? Commented Dec 9, 2021 at 15:50

1 Answer 1

-1

So if I'm reading this correctly you want to show something on mobile but hide it on desktop? If so this can be achieved using media queries.

@media screen and (min-width: 768px) {
  .hide-on-mobile {
    display: none;
  }
}
<div class="hide-on-mobile">
  <p>Code to hide</p>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

no, I want to disable script tag for mobile view

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.