Without knowing "html before" and "html after" can anyone fathom any
reason why the following code crashes IE but if I add <br/> after ANY
<input> tags it doesn't?
*************** *************** *************** *********
HTML = "html before";
HTML += "\
<label for='m-bx'>X:</label><input type='text' id='m-bx'/>\
<label for='m-by'>Y:</label><input type='text' id='m-by'/>\
<label for='m-bw'>Width:</label><input type='text' id='m-bw'/>\
<label for='m-bh'>Height:</label><input type='text' id='m-bh'/>"
HTML += "html after";
bEditor = document.create Element("DIV");
bEditor.innerHT ML = HTML;
dW.appendChild( bEditor);
*************** *************** *************** *********
Nov 5 '05
14 6095
On 06/11/2005 13:19, VK wrote:
[Line separators in string literals] As there are not any mentions of this in official ECMA [...] docs [...]
It's mentioned three times in ECMA-262, and each time it's stated as
forbidden:
A line terminator cannot occur within any token, not even a
string.
-- par. 1, sentence 4, 7.3 - Line Terminators
Escape Sequence ::
CharacterEscape Sequence
0 [lookahead ∉ DecimalDigit]
HexEscapeSequen ce
UnicodeEscapeSe quence
CharacterEscape Sequence ::
SingleEscapeCha racter
NonEscapeCharac ter
NonEscapeCharac ter ::
SourceCharacter but not EscapeCharacter or LineTerminator
-- Syntax, 7.8.4 - String Literals
Repeated in Annex A - Grammar Summary
A 'LineTerminator ' character cannot appear in a string literal,
even if preceded by a backslash \. The correct way to cause a
line terminator character to be part of the string value of a
string literal is to use an escape sequence such as \n or
\u000A.
-- Note, (end of) 7.8.4 - String Literals
[snip]
Mike
--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jim Ley wrote: It's worked just about everywhere always, the big difference is what is in the string, some UA's have a \n in the string, others don't.
It's been generally possible for years, it's still a bad idea, as Richard Cornford noted, it's not part of ECMASCript, it's an extension, and as it doesn't add anything we can already do, there's no point taking the risk.
The referenced paragraph 7.3 of ECMA-262 doesn't deal with this
situation. It explicetly prohibits syntacs like:
(a)
var myString = "Lorem
ipsum";
// Invalid syntacs
In case such:
(b)
var myString="Lorem \
ipsum";
....it goes by the common lexical conventions rules as in paragraph 7.0
While reading the source code fragment (b) interpreter gets (for
Unix-edited text):
var
[space]
myString
=
[string literal begins]
Lorem
[new line escape sequence]
[space]
ipsum
[string literal ends]
It has no means to see that it's a "beauty new line" so the token scan
results are:
[variable]
myString
[assign]
"Lorem \n ipsum"
Same for Macintosh-edited text (with \r instead of \n)
For Windows-edited text (\r\n sequence) \r gets escaped and \n by
itself is not a line terminator, just a "trash symbol" to ignore.
So it's all perfectly ECMA-compliant (not an ECMA extention) and
actually the only way the token search can be done within the current
specifications (so FireFox acts in the same way as others).
I just never tried to read the situation in this way until this case.
Michael Winter wrote: It's mentioned three times in ECMA-262, and each time it's stated as forbidden:
<snip>
As I mentioned above, all these "forbiddens " are not implementable for
the situation in question, because interpreter gets not a screen
snapshot of your code but the code char sequence itself so in case of
"Lorem\
ipsum"
it sees [quot]Lorem[space][new line escape sequence][space]ipsum[quot]
and it has absolutely no means to tell what this [new line escape
sequence] stays from, so it just includes the sequence in the string
value.
The only way to fix it would be to declare illegal any line breaks
sequences until the closing quote, but it would make illegal strings
like "Lorem \n ipsum" so it is not an option.
So
"Lorem\
ipsum"
syntacs seems to be a best practice / bad practice question but not
something that could be ever prohibited/blocked by the parsing engine.
On 06/11/2005 15:02, VK wrote: Michael Winter wrote:
It's mentioned three times in ECMA-262, and each time it's stated as forbidden: As I mentioned above, all these "forbiddens " are not implementable for the situation in question,
Yes, they are. You did read what I quoted, right?
because interpreter gets [...] the code char sequence itself so in case of "Lorem\ ipsum"
it sees [quot]Lorem[space][new line escape sequence][space]ipsum[quot]
And that 'new line escape sequence' is expressely forbidden by both the
grammar and the prose of the specification.
[snip]
The only way to fix it would be to declare illegal any line breaks sequences until the closing quote
That is precisely the case. No line terminator characters are allowed
anywhere within a string literal.
but it would make illegal strings like "Lorem \n ipsum" [...]
No, it wouldn't. That literal doesn't contain a line terminator
character. It contains an escape sequence that will be translated into a
line terminator when the string value (SV) of the literal is determined,
but that is a different matter.
[snip]
Mike
--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Janwillem Borleffs wrote: Richard Cornford wrote: You appear to be trying to escape literal line terminators. ECMA 262 explicitly forbids that when it says (in section 7.2) "A line terminator cannot occur within any token, note even a string literal.". So crashing IE may be an extreme example of not working, but failing to execute would be a reasonable expectation of this code as written.
However, the following renders just fine on IE6, FF and Opera:
http://playground.jwscripts.com/js-lineseparator.php
So it appears that in some cases, line separators can be applied just fine...
And in the next 3 browsers?
Any javascript implementation following the standard will regard it as a
syntax error. It is difficult to test for language extensions that
represent syntax errors (and then conditionally act upon those tests
without exposing the unparsable code where the extension is not
supported), and there is no need to try to escape line terminators as
they are already available as escape sequences anyway. Why write
something that should break but may not in all browsers when you can
just as easily write something that has no excuse for causing problems?
Richard. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Nicolas Van Lancker |
last post by:
Hi folks;
I have this webpage, allowing users to insert multiple records in one post
into the database.
Because I don't know the exact number of records they want to add, I created
a little javascript
that adds a new line with HTML inputboxes and lists to the form if they
press a button.
|
by: necromonger |
last post by:
Hi,
I've got this code that creates a new new row and cell. I then put some
text into the cell with innerHTML - works beautifully with Firefox but
fails with IE. I guess IE doesn't support this way of doing it, but is
there another way of doing it with DOM?
newr = document.createElement('tr');
stbl.appendChild(newr);
|
by: jhcorey |
last post by:
I am doing some maintenance on a js tree control that was done with
proprietary IE code.
When I click on a node it calls a function which has code similar to
that below to expand the tree. "el" refers to the div that I clicked
on.
var workHtml = el.innerHTML;
for (i = 0; i < idx; i++)
|
by: RobG |
last post by:
I know you aren't supposed to use innerHTML to mess with table
structure, but it seems you can't use it just after a table without
damaging the containing element.
I added a table to a div using createElement methods, then added a bit
of extra text using innerHTML, only to find most of the attributes
removed from the table.
Below is a script that calls the same code to add a table inside a
div. It adds an onclick to the div and...
|
by: Jake Barnes |
last post by:
This weekend I wanted to learn AJAX, so I set up a little toy page
where I could experiment. The idea of this page is that you click in
one of the boxes to get some controls, at which point you can add text,
images, or HTML to the box. This seems to work fine in FireFox, but not
in IE. You can see the problem here:
http://www.publicdomainsoftware.org/ajaxExperiment.htm
In FireFox, if you click in a box and then select "Add HTML" you...
| |
by: sonic |
last post by:
Ok,
i am sure everyone is sick of hearing about this. but i've checked
about 10 different posts/sites about this issue, and they all say "use
DOM" but i think there is more to be said. Perhaps I am a total newbie
but the answer was not immediately obvious to me here.
so.. problem:
declaring doctype as xhtml will prevent myDiv.innerHtml=val from
working.
suggested solution:
|
by: SkyZhao |
last post by:
if i use AttachEvent like this,it can't work;
eg:
var img = document.createElement("img");
img.attachEvent("onclick",alert("test"));
var div = document.createElement("div");
div.appendChild(img); //can't work;
div.innerHTML="<-click this";
|
by: Dan Andrews |
last post by:
Hello,
I was wondering what is the correct way to handle special characters
via javascript and the DOM. I would like to avoid document.write and
innerHTML. What I am doing is dynamically creating options for a
select. The innerHTML example below works for firefox and internet
explorer, but is this the accepted way of dynamically adding special
characters.
option = document.createElement("OPTION");
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |