0

How do I stop this --!DOCTYPE html-- with two scripts in it from running on mobile devices?

Hiding the div with the URL in it does not work, so apparently stopping one or both of the scripts is necessary. Thanks!

<!DOCTYPE html>
<html>
<script>
function includeHTML() {
  var z, i, elmnt, file, xhttp;
  /*loop through a collection of all HTML elements:*/
  z = document.getElementsByTagName("*");
  for (i = 0; i < z.length; i++) {
    elmnt = z[i];
    /*search for elements with a certain atrribute:*/
    file = elmnt.getAttribute("w3-include-left-html");
    if (file) {
      /*make an HTTP request using the attribute value as the file name:*/
      xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4) {
          if (this.status == 200) {elmnt.innerHTML = this.responseText;}
          if (this.status == 404) {elmnt.innerHTML = "Page not found.";}
          /*remove the attribute, and call this function once more:*/
          elmnt.removeAttribute("w3-include-left-html");
          includeHTML();
        }
      }      
      xhttp.open("GET", file, true);
      xhttp.send();      
      /*exit the function:*/
      return;
    }
  }
};

</script>

<body>

<div w3-include-left-html="borders/border-left.html"></div> 

<script>
includeHTML();
</script>

</body>
</html>
Yogani
  • 1
  • Your HTML isn't valid. The only elements allowed inside `` are `head` and `body`. –  Mar 25 '18 at 00:07
  • Why do you select `"*"` for all nodes, when you could just use a `".wc-include-left-html"` selector to get just the nodes you're interested in? –  Mar 25 '18 at 00:09
  • You could always use css media queries to hide or reformat stuff you don't want to see by default on mobile – Ibu Mar 25 '18 at 00:21

1 Answers1

0

Detect a mobile browser using one of the methods here:

Detecting a mobile browser

If detected, return immediately.

Eg

<script>
function includeHTML() {
  if (mobilecheck()) {
      return;
  }

... code to run on desktops only

</script>
Kingsley
  • 977
  • 2
  • 11
  • 27
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
  • Thank you. Not there yet for stopping some of the script(s) on mobile, but working on it. The !DOCTYPE html comes from W3 here: https://www.w3schools.com/howto/howto_html_include.asp This enables menus to be inserted dynamically (server side) from single HTML files to thousands of pages on a website. That is why we use it, and it works well. – Yogani Mar 25 '18 at 02:37