Data output from Javascript

Alex M. Andrew (Department of Cybernetics, University of Reading (retired), Reading, UK)

Kybernetes

ISSN: 0368-492X

Article publication date: 12 October 2012

1918

Abstract

Purpose

The purpose of this paper is to review the advantages of the Javascript programming language for demonstration programs. A major disadvantage is the difficulty of exporting data from such programs, felt particularly when graphical output is wanted. The paper describes and compares two ways of overcoming the difficulty.

Design/methodology/approach

One of the methods depends on transferring data from the screen display via the “clipboard”; the other involves transfer of data into e‐mail messages.

Findings

The “clipboard” method is the simpler and more intuitive of the two and was used by the author to produce graphs, but the e‐mail method could be advantageous where larger amounts of data have to be transferred.

Practical implications

Both of the methods are extremely tedious in use, and where data has to be transferred repeatedly, for instance in studies where repeated inspection of results in graphical form is needed, the solution would almost certainly be to choose a programming language other than Javascript.

Originality/value

The paper discusses what is believed to be a novel method of transfer of data using e‐mail.

Keywords

Citation

Andrew, A.M. (2012), "Data output from Javascript", Kybernetes, Vol. 41 No. 10, pp. 1604-1606. https://doi.org/10.1108/03684921211276774

Publisher

:

Emerald Group Publishing Limited

Copyright © 2012, Emerald Group Publishing Limited


Javascript

The Javascript programming language can be useful for writing demonstration programs, for example by Andrew (2011). It has the advantage of having an interpretive running system available in all modern internet browsers, as well as means of modifying the program itself if desired using a simple word processor such as Notepad. The ALGOL‐type language is rather primitive but with a little ingenuity much can be done with it. In particular, complex tree‐search procedures of the kind often used in AI can sometimes be achieved rather nicely by using the “string” variables of Javascript as stacks.

However, a major disadvantage arises from precautions taken to protect computer users from malicious interference by Javascript programs on the internet. As a part of this, Javascript programs are prevented from writing to files, and any means of collecting or storing data from a run must be essentially a means of circumventing this precaution. A particular reason for wishing to do so is that the language has no facility of its own for graphical output and in order to produce graphs rather large amounts of numerical data must somehow be transferred to a different package such as Microsoft Excel.

Data transfer

The means used to transfer data to produce the graphs shown in Andrew (2011) was to let chunks be displayed on the computer screen, then “wiped” using the mouse pointer and transferred to the “clipboard”, from which they were transferred to files in Microsoft Notepad and from these to the Excel spreadsheet. The method is effective though tedious. The purpose of the present note is to describe an alternative that may be felt to be more elegant, and could be advantageous when very large amounts of data have to be transferred.

What is claimed to be a means of transferring data between Javascript and Java environments is entitled “LiveConnect” and described by Leonardo (1997). I have to admit to having failed to understand or evaluate this, and in any case Java applets are subject to restrictions similar to those that apply to Javascript programs, imposed for the same reasons. There could be a possibility here, though, if Java is activated in a non‐applet version.

An alternative to the “clipboard” method of exporting data, believed to be novel, depends on exporting it as content of e‐mail messages. It is suggested by an earlier anti‐spam scheme (Andrew, 2007) in which an e‐mail address is assembled from its parts and inserted in a generated “form”. Clicking on the form then activates an instruction that allows the e‐mail to be sent. The fact that the address is assembled from parts prevents it being recognised as an address and so collected by automatic “bots” for malicious or nuisance use. It should be mentioned that a simpler scheme was devised much earlier by another worker called Joe Maller (Andrew, 2008) and it is probably sufficient to give protection against existing address‐collecting “bots” though the later scheme can be argued to give still greater security.

An e‐mail address such as [email protected] is often incorporated in the HTML of a website as a link in the following form:

Fixed graphic 1

The text that is between the tags <a> and </a>, in this case: “e‐mail for ABC” appears when the web site is viewed, and clicking on it with the mouse causes an e‐mail form to be opened with the given e‐mail address at its head. The anti‐spam scheme due to Andrew operates to construct a link conforming to the above within a generated text‐box also referred to as a “form”.

However, a link of this sort can carry much more information, as is clear from the implementation of another anti‐spam method. One way of avoiding the appearance of the giveaway “@” is to replace it by text such as “AT” or “_AT_” and to ask the writer of the e‐mail message to make the necessary substitution. A convenient way to make the request is to insert it in the link following a question mark and its assignment to “body”, as.

Fixed graphic 2

This last example is taken from the web site of the UK Cybernetics Society and provides a means of generating an e‐mail message to the President, with the address initially appearing as “president AT cybsoc.org”, to be changed by the user to [email protected]. The polite message requesting the change appears as the initial content of the body of the message.

As well as making the assignment to “body” an assignment can also be made to “subject”, with the assignments separated by the character “&”. (Assignments can also be made to “cc” for “carbon copies” and to “bcc” for “blind carbon copies” but these are not used in the present application).

Program

For the purpose of forming “Daisyworld” graphs, when done by this method, separate e‐mail messages are used to convey the contents of each of a number of arrays, each of 66 ordinates. A beginning and an end for each link of the required kind are formed by functions declared as follows:

Fixed graphic 3

The transfer then depends on producing a “form” as a new window, as was done in the anti‐spam scheme (Andrew, 2007), with the link formed as “tempWindow” and assembled as follows (shown here in the case of the graph for bare ground, with the values stored in an array tBare):

Fixed graphic 4

The e‐mail messages that convey the data have a fictitious destination address inserted by the function link 1. If the program is run without an internet connection the messages can be retrieved from the outbox and their contents passed to the Excel spreadsheet. (If it is run with an internet connection the messages will be retrievable from the “Sent” box and a set of notifications of delivery failure can be expected).

A small practical point is that the method works readily with Windows XL, and also works with Windows 7, though when the latter is used the system detects an irregular situation and the user must give permission by clicking on “allow blocked content”.

Conclusions

The two methods of data transfer – using the clipboard and using e‐mail messages – extend the possibilities of using Javascript as a medium for demonstration programs and possibly other applications. On the other hand, both methods are extremely tedious to apply, and would be prohibitively so for any study requiring repeated plotting and inspection of graphs. For such work a different programming language is needed.

 Fixed graphic 1

Fixed graphic 1

 Fixed graphic 2

Fixed graphic 2

 Fixed graphic 3

Fixed graphic 3

 Fixed graphic 4

Fixed graphic 4

Corresponding author

Alex M. Andrew can be contacted at: [email protected]

References

Andrew, A.M. (2007), “An anti‐spam scheme”, Kybernetes, Vol. 36 No. 2, pp. 2536.

Andrew, A.M. (2008), “Spam and javascript: future of the web (cybernetics and systems on the web)”, Kybernetes, Vol. 37 Nos 9/10, pp. 14635.

Andrew, A.M. (2011), “Daisyworld and physiological rein control”, Kybernetes, Vol. 40 Nos 9/10, pp. 1297304.

Leonardo, L.M. (1997), Using Netscape LiveConnect, Que Corporation, Indianapolis, IN, 353 pp.

Related articles