Wassup with detecting JavaScript?

خرید بک لینک

I'm building a web site. My plan for dealing with the "no-JavaScript" browser is to write the code so that it loads for that user. The first thing JavaScript does when it starts is change some settings so that the site uses the features of JavaScript.

My HTML code is similar to:

<body>
  <div class="content c1"></div>
  <div class="content c2"></div>
  <div class="content c3"></div>
</body>

My CSS is like:

body div.content { display: block }

If I deployed nothing else, all my visitors would see all three divs (the whole site). That's what I want for the no-JS visitors.

My JS is like:

(function myFunction1() {

  function initialize() {
    // window.removeEventListener("load", initialize, false) // *1
    document.removeEventListener("DOMContentLoaded", initialize, false) // *1
    // appropriate code summarized as:
    // register event listeners on buttons the user pushes to move between divs
    // div.c2.style.display = "none"
    // div.c3.style.display = "none" // *2
  }

  // main execution starts here
  // window.addEventListener("load", initialize, false) // *3
  document.addEventListener("DOMContentLoaded", initialize, false) // *3
  retu {}
})()

This code uses an event listener *3 to prevent running the initialize() function early. In initialize(), we delete the event listener we'll never need again *1 and run a series of statements to use JavaScript effectively. We hide div.c2 and div.c3 (leaving only div.c1 displayed) and install other event listeners and buttons the users click or push to see the other divs.

I present a couple options for addEventListener() here (*1 and *3) because three of my four browsers are cranky about it in various ways. I asked why that would happen on StackOverflow (http://stackoverflow.com/questions/38231128/wassup-with-addeventlistener). All reports so far indicate people are unable to reproduce. If the SuperUsers can help with that, I'll much appreciate it (but maybe it's out of scope to your site!)

I can run Firefox, Chrome, IE11, and Edge on this computer. Except for Edge (for which I found no instructions), I've recently disabled JavaScript on each browser to see the behavior of my no-JS code. After completing testing, I used the same instructions, but allowed JavaScript again. Maybe the restorations didn't work.

In current configuration, my code operates as if it cannot use JS on IE11 and Firefox. I've checked all four browsers at http://www.enable-javascript.com/; all but Firefox reports JavaScript enabled. (Yup. IE11 reports enabled and acts otherwise.)

That page gave me instructions for enabling JavaScript in Firefox. Sadly, after doing those, that page continues to report JavaScript is not enabled.

EDIT: My bad, at least half. On http://www.enable-javascript.com/ with Firefox, the problem was NoScript. It was dutifully showing a line at the bottom asking if I would accept JavaScript from the site. When I accepted, it indicated (as expected) that JavaScript is enabled.

EDIT cont'd*: On the other hand, I don't get the option to accept JavaScript for my web site (currently files on my hard disk). And nothing changes when I set NoScript >> Options >> Trusted >> Allow local links.

Most important: Any ideas on what I'm doing wrong with using JavaScript, especially on IE11 and Firefox?

Bonus question; if this is out of scope, please feel free to leave this alone: Any ideas why 3 of my 4 browsers are cranky about addEventListener()?

Thanks in advance.

Recent Questions...

ما را در سایت Recent Questions دنبال می‌کنید

برچسب: نویسنده: استخدام کار بازدید: 680 تاريخ: پنجشنبه 17 تير 1395 ساعت: 3:22

صفحه بندی