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


Groups > comp.lang.javascript > #26381 > unrolled thread

TXT file into Iframe causes warning

Started byDr J R Stockton <reply1400@merlyn.demon.co.uk.invalid>
First post2014-12-25 12:03 +0000
Last post2015-01-02 07:34 -0800
Articles 4 — 3 participants

Back to article view | Back to comp.lang.javascript


Contents

  TXT file into Iframe causes warning Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-12-25 12:03 +0000
    Re: TXT file into Iframe causes warning "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-12-26 10:00 +0200
      Re: TXT file into Iframe causes warning Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-12-27 20:20 +0000
    Re: TXT file into Iframe causes warning "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2015-01-02 07:34 -0800

#26381 — TXT file into Iframe causes warning

FromDr J R Stockton <reply1400@merlyn.demon.co.uk.invalid>
Date2014-12-25 12:03 +0000
SubjectTXT file into Iframe causes warning
Message-ID<6NO2IGEp0$mUFwtJ@invalid.uk.co.demon.merlyn.invalid>
I am using Firefox with Tools, Web Developer, Web Console (Ctrl-Shift-K)
and this code :-

        function RequestData() {
          addCallback(Ifr1, "load", SelectReadings)
          Ifr1.src = E7form.Fname.value.trim() }

        function SelectReadings() { var Lines
          removeCallback(Ifr1, "load", SelectReadings)
          Lines = Ifr1.contentDocument.body.innerHTML.split(/\n/)
          ...

The page executing the code, and the file named in FName, are both on my
Windows C: drive, and the file, which is plain seven-bit text and
numbers in a *.TXT file, shows in the iframe pointed to by Ifr1, and
Lines receives the correct contents.

BUT - Web Console gives the Warning  "! The character encoding of a
framed document was not declared. The document may appear different if
viewed without the document framing it."  which is annoying.

Can, and if so how can, this particular warning be eliminated, by
altering the beginning of the TXT file or by altering the displaying
page/script or both?

BTW, the code works for me in some other browsers, but not in Chrome.



Observation :-

It is very easy to present the results of a set of calculations in a
TextArea, but AFAICS there is no direct provision for printing the
content of a TextArea.  It is sufficiently easy to transfer the content
of the TextArea, adding PRE and changing \n to <br>, to an Iframe (and
to get the same result without using the TextArea).  In Firefox at
least, a right click in the Iframe enters a direct route to printing out
_only_ the content of the frame.  The following code fragment could
provide sufficient clues :-

  Ifr2.src = "javascript:'<pre>" + Arr2.join("<br>") + "<\/pre>'"
  Ifr2.style.height = Arr2.length*2.7 + "ex"

One can also add HTML formatting into the contents of Arr2.

-- 
 (c) John Stockton, nr London, UK.  For Mail, see Home Page.  Turnpike, WinXP.
 Web  <http://www.merlyn.demon.co.uk/> - FAQ-type topics, acronyms, and links.
 Command-prompt MiniTrue is useful for viewing/searching/altering files. Free,
 DOS/Win/UNIX now 2.0.6;  see my <http://www.merlyn.demon.co.uk/pc-links.htm>.

[toc] | [next] | [standalone]


#26386

From"Jukka K. Korpela" <jkorpela@cs.tut.fi>
Date2014-12-26 10:00 +0200
Message-ID<m7j4hf$9v2$1@dont-email.me>
In reply to#26381
2014-12-25, 14:03, Dr J R Stockton wrote:

> BUT - Web Console gives the Warning  "! The character encoding of a
> framed document was not declared. The document may appear different if
> viewed without the document framing it."  which is annoying.

This issue can be reproduced simply by using, in a local document, an 
<iframe> element that refers to a local plain text document, with just 
<iframe src=foo.txt></iframe>. So the issue has really nothing to do 
with JavaScript as such, and it seems there there is no JavaScript 
solution either (browsers recognize contentDocument.characterSet for an 
iframe element, but it is not writeable).

> Can, and if so how can, this particular warning be eliminated, by
> altering the beginning of the TXT file or by altering the displaying
> page/script or both?

It can be eliminated by saving the plain text document as UTF-8 encoded 
with BOM. This makes browsers auto-recognize it as UTF-8 encoded even in 
the absence of HTTP headers. Of course, any processing of the data then 
needs to skip the first three bytes in the file.

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

[toc] | [prev] | [next] | [standalone]


#26389

FromDr J R Stockton <reply1400@merlyn.demon.co.uk.invalid>
Date2014-12-27 20:20 +0000
Message-ID<DiUIj4BHSxnUFwA9@invalid.uk.co.demon.merlyn.invalid>
In reply to#26386
In comp.lang.javascript message <m7j4hf$9v2$1@dont-email.me>, Fri, 26
Dec 2014 10:00:09, Jukka K. Korpela <jkorpela@cs.tut.fi> posted:

>2014-12-25, 14:03, Dr J R Stockton wrote:
>
>> BUT - Web Console gives the Warning  "! The character encoding of a
>> framed document was not declared. The document may appear different if
>> viewed without the document framing it."  which is annoying.
>
>This issue can be reproduced simply by using, in a local document, an
><iframe> element that refers to a local plain text document, with just
><iframe src=foo.txt></iframe>. So the issue has really nothing to do
>with JavaScript as such, and it seems there there is no JavaScript
>solution either (browsers recognize contentDocument.characterSet for an
>iframe element, but it is not writeable).

The non-existence of a JavaScript solution, where one might reasonably
be hoped for, must be on-topic in a JavaScript group.


>> Can, and if so how can, this particular warning be eliminated, by
>> altering the beginning of the TXT file or by altering the displaying
>> page/script or both?
>
>It can be eliminated by saving the plain text document as UTF-8 encoded
>with BOM. This makes browsers auto-recognize it as UTF-8 encoded even
>in the absence of HTTP headers. Of course, any processing of the data
>then needs to skip the first three bytes in the file.

Wikipedia has provided what I needed to understand that.  My preferred
editor cannot save plain text as anything other than DOS or UNIX.  But
it has no objection to inserting the three characters "0xEF, 0xBB, 0xBF"
= '' (which string may not travel well) from their decimal values at
the beginning of the data file.  The code reading the iframe ignores all
lines not containing at least three decimal numbers each of at least
five digits, so an initial line containing a BOM with an attribution to
JKK is, with no further effort, not processed.

Thanks.

-- 
 (c) John Stockton, Surrey, UK.  ¬@merlyn.demon.co.uk   Turnpike v6.05   MIME.
   Web  <http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.

[toc] | [prev] | [next] | [standalone]


#26435

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2015-01-02 07:34 -0800
Message-ID<f9c82665-7c78-4a21-a2d7-8ffc00bc209d@googlegroups.com>
In reply to#26381
On Thursday, December 25, 2014 5:45:26 PM UTC-6, Dr J R Stockton wrote:
> The page executing the code, and the file named in FName, are both on my
> Windows C: drive, and the file, which is plain seven-bit text and
> numbers in a *.TXT file, shows in the iframe pointed to by Ifr1, and
> Lines receives the correct contents.
> 
> BUT - Web Console gives the Warning  "! The character encoding of a
> framed document was not declared. The document may appear different if
> viewed without the document framing it."  which is annoying.
> 
> Can, and if so how can, this particular warning be eliminated, by
> altering the beginning of the TXT file or by altering the displaying
> page/script or both?

From limited testing, the following seems to work:

<!doctype html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
      <title>iframe text load test</title>
  </head>
  <body>
    <iframe id="frmText" src="data:text/plain;charset=utf-8,Hola%20Mundo"></iframe>
  </body>
</html>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web