Skip to main content

Forums

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #194011
    tinusmile
    Participant

    I have a script that I want only for mobile. Here’s the code I use:

    if (document.documentElement.clientWidth <= 768) {

    // script

    }

    How do I get the script reloaded (not the page) at e.g. an orientation change on tablets or at resizing the browser window on desktop views?

    Thanx!

    #194014
    Shikkediel
    Participant

    You can add an event listener and put your existing function inside it…

    window.addEventListener('resize', function() {
    
    // your code
    });
    

    Browsers before IE9 need a separate approach.

    #194052
    Chromawoods
    Participant

    If you find yourself doing this a lot, then you might want to use something like jRespond:

    https://github.com/ten1seven/jRespond

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
icon-link icon-logo-star icon-search icon-star