0

I'm currently working on building a site with a responsive design. As part of that I need to prevent the below code from executing if the user visits the website using a mobile device. How can I achieve that?

The code:

var leftHeight = $("#sidebar").height();
var rightHeight = $("#main").height();
if (leftHeight > rightHeight){ $("#main").height(leftHeight)}
else{ $("#sidebar").height(rightHeight+25)};

function equalHeight() {
    var heightArray = $("#footer>div.box").map(function () {
        return $(this).height();
    }).get();

    var maxHeight = Math.max.apply(Math, heightArray);
    $("#footer>div.box").height(maxHeight);
}
equalHeight();
Anthony Grist
  • 38,173
  • 8
  • 62
  • 76
Maanstraat
  • 1,241
  • 7
  • 34
  • 63
  • How are you determining if the user is on a mobile device? – tymeJV Jun 19 '13 at 14:06
  • So you want to not execute that entire block of code if they're on a mobile device? – Anthony Grist Jun 19 '13 at 14:07
  • @Anthony Grist thats right! – Maanstraat Jun 19 '13 at 14:10
  • Are you sure you want to prevent the code from running on mobile devices or do you want to prevent the code from running for a certain view size? (I assume you you use media queries to have different layouts and for a certain layout this script should not run?) – t.niese Jun 19 '13 at 14:19
  • t.niese, i use the media queries, yes. When the window is smaller then 980px the functions must not work anymore. – Maanstraat Jun 19 '13 at 14:23
  • @Maanstraat, but what if i change the window to a size smaller then `980px` on my desktop or laptop. Would the script then behave correctly ? – t.niese Jun 19 '13 at 14:25

1 Answers1

-1

I think i have found a solution:

if (document.documentElement.clientWidth < 980 ) {
    $("#sidebar").height("auto");
    $("#footer .box").height("auto");
}
Maanstraat
  • 1,241
  • 7
  • 34
  • 63
  • How gave this a **-1** and why? I know the Question is about detection mobile device. But depending on the requirement this is the right solution, instead of testing for the mobil device. – t.niese Jun 19 '13 at 14:28
  • If you write an answer you should explain what you did and why, especially if your answer (solution) does not exactly match the question (even if it is yours). – t.niese Jun 19 '13 at 14:33