Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Reloading javascript at orientation change

  • 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)
  • The forum ‘JavaScript’ is closed to new topics and replies.