![]() | |
![]() |
| | Thread Tools | Display Modes |
#31
| |||
| |||
|
|
Dr J R Stockton wrote: In effect, I want to read the file, HTML or TXT, as it exists on disc. VK wrote: You cannot do it for the reason explained at http://groups.google.com/group/comp.lang.javascript/msg/d9f3f6724bada573 Dr J R Stockton wrote: Unconvincing, because I *am* doing it, VK wrote: You don't, it is your delusion. I don't know how and why are you doing it, but it was stated that "I want to read the file, HTML or TXT, as it exists on disc." As long as you are not using AJAX calls - and you don't - you are not able and you are not reading any files "HTML or TXT, as it exists on disc" - however wide the definition "as it exists on disc" would be taken. Dr J R Stockton wrote: Give or take irrelevant questions of character coding and newline representation, I have been getting, by using innerHTML and by using innerText, a string which agrees visually with the content of a TXT file on disc, as would be shown by Notepad. It should be expected in many (but not all) situations. Contrary to the popular believe, browsers are *not* able to open text or graphics files. What they are able to - as part of their extended functionality - is to recognize some file types other than HTML and to wrap them on the fly into predefined HTML templates so to display them in the browser window. In the particular for text/plain files they are using template HTML HEAD></HEAD BODY PRE> text file content goes here </PRE /BODY /HTML with the exact tags' case (upper or lower) being browser dependent. |
|
This way the text you "see" is in effect the content of a single <pre element necessarily altered from the "as it is on disc" to be placed into this tag. For instance all less-than and greater-than signs will be converted to the corresponding named HTML entities. The fact that you were getting so far "by using innerHTML ..., a string which agrees visually with the content of a TXT file" suggests that so far you were lucky but not having any problematic characters in your .txt files, |
|
Associated query : I have read a TXT file from disc, getting a matching string. *It consists of many lines containing words separated by punctuation. *They all start with the same sequence of words and punctuation (improbably, zero length), but after that there is always non-zero length. *No two lines completely agree. *What is the nicest way of determining the common part AND obtaining in sequence strings for the varying parts? *Think of it as like a representation of a directory tree. This is OT to the discussed FAQ topic but an interesting problem per se. I am thinking to move it into separate thread or you may do it yourself. I have a rather close request for ggNoSpam, in order to give users an ability to adjust the regexp spam filter even with zero knowledge of regular expressions. The abstract task description would be: "Given an array of strings with the minimum 2 and the maximum 1o elements, find the shortest common word in these strings. If no such common character sequence found, then try to find the biggest subset of strings having a common word". "word" is understood in regexp terms. To avoid "rush answers" with common words like "a" or "the" articles let's define that the shortest common word must be no shorter than 4 characters. |
#32
| |||
| |||
|
|
In comp.lang.javascript message <hcdshu$ds2$1 (AT) news (DOT) eternal- september.org>, Thu, 29 Oct 2009 22:11:19, Garrett Smith dhtmlkitchen (AT) gmail (DOT) com> posted: As long as I have something to say about it, the entry will correctly explain how to access the window object of the IFRAME. You are supposed, as FAQ maintainer, to be sustaining something useful to the ordinary questioners, especially those who are not full-time professional JavaScript programmers. However, you appear entirely unable to understand their positions and points of view. FAQ maintaining is a task for the sympathetic communicator; not for the nerd. |
|
The frame must be fully loaded before its content can be accessed. fwin.document;// the document fwin.document.documentElement; // root element. See the section on DOM and Forms: #domRef |
#33
| |||
| |||
|
|
In comp.lang.javascript message <53e60b5e-ddec-4b97-aa14-64c31f883159@j1 9g2000yqk.googlegroups.com>, Sat, 31 Oct 2009 10:08:13, VK schools_ring (AT) yahoo (DOT) com> posted: Dr J R Stockton wrote: In effect, I want to read the file, HTML or TXT, as it exists on disc. VK wrote: You cannot do it for the reason explained at http://groups.google.com/group/comp.lang.javascript/msg/d9f3f6724bada573 Dr J R Stockton wrote: Unconvincing, because I *am* doing it, VK wrote: |
|
This way the text you "see" is in effect the content of a single <pre element necessarily altered from the "as it is on disc" to be placed into this tag. For instance all less-than and greater-than signs will be converted to the corresponding named HTML entities. The fact that you were getting so far "by using innerHTML ..., a string which agrees visually with the content of a TXT file" suggests that so far you were lucky but not having any problematic characters in your .txt files, "getting by using innerHTML" is not the same as "getting directly as innerHTML". IIRC, most browsers wrapped with <pre> and one put rather more at the top. When I was using innerHTML, I easily removed those by RegExp. |
#34
| |||
| |||
|
|
You might try reading from the PRE element: var fdoc = frames[0].document; var pre = fdoc.getElementsByTagName("pre")[0]; var htmlString = pre.innerHTML; var textString = (typeof pre.textContent == "string" ? pre.textContent : pre.innerText); |
#35
| |||
| |||
|
|
Dr J R Stockton wrote: In comp.lang.javascript message <hcdshu$ds2$1 (AT) news (DOT) eternal- september.org>, Thu, 29 Oct 2009 22:11:19, Garrett Smith dhtmlkitchen (AT) gmail (DOT) com> posted: As long as I have something to say about it, the entry will correctly explain how to access the window object of the IFRAME. You are supposed, as FAQ maintainer, to be sustaining something useful to the ordinary questioners, especially those who are not full-time professional JavaScript programmers. However, you appear entirely unable to understand their positions and points of view. FAQ maintaining is a task for the sympathetic communicator; not for the nerd. A lot of the complaints with the FAQ is too verbose, too long. The FAQ should not be too much of a chore to read. It should be easy to understand. Once the document is found, the next step is to do something with that, right? That is what DOM and Forms section is for. Things about the document seem more appropriate for "DOM and Forms", not "window and frames". |
|
Perhaps worth mentioning:- | The frame must be fully loaded before its content can be accessed. |
|
How can I know when an iframe has loaded? |
#36
| |||
| |||
|
|
Garrett Smith : How can I know when an iframe has loaded? Yes. I have success with the Fram.onLoad event in FF Op Sf Cr, but not IE, where I seem to need to use a timeout. OTOH I suspect IE8 of lying to me, or of being confused[*]. Flamingo wrote of a readyState property, which might be pollable. |
#37
| |||
| |||
|
|
Dr J R Stockton wrote: In comp.lang.javascript message <hcj02m$62n$1 (AT) news (DOT) eternal- september.org>, Sat, 31 Oct 2009 19:42:12, Garrett Smith dhtmlkitchen (AT) gmail (DOT) com> posted: Dr J R Stockton wrote: In comp.lang.javascript message <hcdshu$ds2$1 (AT) news (DOT) eternal- september.org>, Thu, 29 Oct 2009 22:11:19, Garrett Smith dhtmlkitchen (AT) gmail (DOT) com> posted: As long as I have something to say about it, the entry will correctly explain how to access the window object of the IFRAME. You are supposed, as FAQ maintainer, to be sustaining something useful to the ordinary questioners, especially those who are not full-time professional JavaScript programmers. Would an ASCII diagram for the FRAMES section help? |
![]() |
| Thread Tools | |
| Display Modes | |
| |