473,434 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

"print" in JavaScript


I have just had a problem that I cannot find any reference to in any
docs. Admittedly, I am a JavaScript newbie, but this sure seems like a
bug or an "undocumented feature" in Opera 7.11. I have some debugging
code that writes messages to a TEXTAREA. I named the function that
writes to the TEXTAREA "print", e.g.

content = "";
cnt = 0;
function print(aLine) {
content += (aLine + "\n");
cnt++;
document.getElementById.transcript.value = content;
};
print("some message");

The problem is that when I accidently mis-specified a DOM path to point
to an .html page and invoked "print", e.g.

print(self.parent.frames.transcript);

then Opera gave me a popup Print Dialog. I replied OK and got printout
of the page currently being displayed by Opera. I looked in the docs
and "print" is not a reserved word in JavaScript. Can anyone tell me
what is going on?

--
Don't you see that the whole aim of Newspeak is to narrow the range of
thought? In the end we shall make thoughtcrime literally impossible,
because there will be no words in which to express it.
-- George Orwell, 1984

Jul 20 '05 #1
3 3526
I just discovered that Opera 7.11 does in fact implement a "print()" as
a non-standard extension to ECMA. Still, it is a peculiar
implementation: all of my "print" statements do in fact end up in my
TEXTAREA except when I inadvertantly try to print a page. Whatever...I
changed all occurances of print to tprint. Not a problem, just a
mystery.

--
Don't you see that the whole aim of Newspeak is to narrow the range of
thought? In the end we shall make thoughtcrime literally impossible,
because there will be no words in which to express it.
-- George Orwell, 1984

Jul 20 '05 #2
"Albert Wagner" <al******@tcac.net> wrote in message
news:20030918190229.2ee43bb1.al******@tcac.net...
I just discovered that Opera 7.11 does in fact implement a
"print()" as a non-standard extension to ECMA. Still, it
is a peculiar implementation: all of my "print" statements
do in fact end up in my TEXTAREA except when I
inadvertantly try to print a page. Whatever...I changed
all occurances of print to tprint. Not a problem, just a
mystery.


The ECMA script specification describes a scripting language. It is the
intention that it be used to script an object model. In a web browser
that object model is implemented by the browser and consists of a
structure of objects (generally tree like and rooted at the global
object (the window object)) some of which have methods specific to web
browsers.

print() is implemented as a function property of the global object in
many web browsers to allow the scripting of the browser's ability to
print web pages and will usually open the print dialog box. This mans
that print is not a non-standard extension of ECMA script, it is not
part of ECMA script at all.

Generally it is unwise to use element names, IDs or JavaScript
identifiers that correspond with existing defined properties within the
browser object model, especially properties of the global object. Though
your specific problem would only manifest itself in browsers that follow
IE in making named/IDed HTML elements named properties of the global
object, unfortunately quite a number of browsers (including Opera 7) do.

Richard.
Jul 20 '05 #3
JRS: In article <bk*******************@news.demon.co.uk>, seen in
news:comp.lang.javascript, Richard Cornford
<Ri*****@litotes.demon.co.uk> posted at Fri, 19 Sep 2003 02:44:41 :-

Generally it is unwise to use element names, IDs or JavaScript
identifiers that correspond with existing defined properties within the
browser object model, especially properties of the global object. Though
your specific problem would only manifest itself in browsers that follow
IE in making named/IDed HTML elements named properties of the global
object, unfortunately quite a number of browsers (including Opera 7) do.


Unfortunately, that otherwise-excellent rule requires a knowledge of all
such existing properties in all such browsers, including those that may
be written after the page in question.

A more pragmatic approach is never to use a name (except in a scope
where a new definition certainly rules) that anyone might, reasonably or
moderately unreasonably, build or have built into a system.

It seems that most lesser-known names in javascript begin with a lower-
case letter; so one could avoid that.

Also, it is commonly convenient when programming to do a general string
search or replace on a page or a page set. Therefore, avoid correctly-
spelt well-known words in the natural language of the page, and in HTML.
Once upon a time, at least one system designer understood this problem.
In software for the Elliott 905, names beginning with Q-but-not-QU
"belonged" to the system software authors. They could be used by
ordinary programmers; they could be redefined, but only at the
programmer's understood risk. All other names were either not used by
the system, or were "well-known".

And in implementations of Algol, "reserved words" were indicated by
punctuation; in some, the word begin was coded as "begin" or
'begin'; in another, as !begin, and then reserved words could be
abbreviated once unambiguous - so !begin could be !be. but not (if
!boolean existed) !b. .
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: vegetax | last post by:
How can i use cgi'like print statement in a multitreaded web framework? each thread has its own Servlet instance with request/response objects, sys.stdout = self.response(which is a file like...
17
by: Geoff Cox | last post by:
Hello, I am trying to have 1. web pages in large font 2. web pages with smaller font for printing I am using <link rel="stylesheet" media="print" type="text/css"
16
by: John Baker | last post by:
HI; I feel like a fool..I put CUTE FTP in my last request for help --it should have been CUTE PDF! I have FTP on my mind because I have been working on a web based application, and somehow my...
5
by: Paul Sullivan | last post by:
We are a state agency that views protected medical information via our intranet. The screens even have privacy shields. Alarmingly, uses can "Print" and "Save As" which destroys the protection of...
1
by: Steff | last post by:
I am wandering if my code is making sense... I use a lot the print function. Is it weird in this case where I have to display an array ? I thought it would be better to have the entire array in php...
2
by: kbperry | last post by:
Hi all, I am getting an error message when trying to use the P4 print command via the python api for perforce. Anytime that I run p4c.run("print","-q", eachFile), I keep getting an error...
1
by: Appu | last post by:
How to Check in the window print dialog box whether we clicked either "print" or "cancel". while clicking a button i call wnidow.print() to pop up the windows PRint Dialog box. I want to check...
10
by: Prisoner at War | last post by:
Hi, your friendly neighborhood n00b here, just wondering why on earth the Py3K folks want to mess with a simple thing like the "print" "command" (is that what it's called, a command?), turning it...
2
by: sixtyfootersdude | last post by:
Good Morning! I am just starting to learn perl and I am somewhat mistifide about when I should do: print("@input"); and when I should do: print(@input)
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.