Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #30295

Re: Ctrl + onload

From emf <emfril@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: Ctrl + onload
Date 2016-04-18 22:13 -0400
Organization Aioe.org NNTP Server
Message-ID <nf447d$qv0$1@gioia.aioe.org> (permalink)
References <nepuha$19br$1@gioia.aioe.org>

Show all headers | View raw


On 2016-04-15 01:34, emf wrote:
> In eye exercise #4, I would like to change this
>
> window.onload = function () {
>      "use strict";
>      var text = "text1.txt";
>      textFile(text);
>      document.getElementById("start").onclick = function () {
>          requestFullScreen();
>          init();
>      };
> };
>
> so that when you open the window while pressing Ctrl (or maybe the "2"
> key) text2.txt instead of text1.txt is assigned to text. Is this possible?
>
> I do not want to use a checkbox or radio buttons.
>
> BTW, textFile(text); has to be executed onload, it cannot be executed
> onclick -- I tried it out and it doesn't work. (Though I guess I could
> have both text files read in 2 different arrays, in which case I might
> select one of the other by pressing Ctrl while clicking the Start
> button...)
>
> BTW, this exercise does not work in Internet Explorer -- something I co
> not consider crucial. I am wondering, though, about Edge...

The problem was solved with this

window.onload = function () {
     "use strict";
     // load both text files
     textFile(0);
     textFile(1);
     document.getElementById("start").onclick = function (e) {
         var i;
         requestFullScreen();
         i = (e.ctrlKey)
             ? 1
             : 0;
         init(i);
     };
};

A couple of comments. Instead of

     textFile(0);
     textFile(1);

initially I had tried to use an for loop, which worked but JSlint found 
the for unexpected, so I deduced that I shouldn't use a for loop in this 
context.

Also I still have difficulty understanding why the e is now necessary in 
the line:

     onclick = function (e) { ...

emf
-- 
Eye exercises
http://emf.neocities.org/ix/eyex.html

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Ctrl + onload emf <emfril@gmail.com> - 2016-04-15 01:34 -0400
  Re: Ctrl + onload emf <emfril@gmail.com> - 2016-04-18 22:13 -0400
    Re: Ctrl + onload Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-04-19 19:46 +0200
      Re: Ctrl + onload Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-04-26 02:55 +0200

csiph-web