Closed Thread Icon

Topic awaiting preservation: Read txt/ascii with JScript? Pages that link to <a href="https://ozoneasylum.com/backlink?for=9007" title="Pages that link to Topic awaiting preservation: Read txt/ascii with JScript?" rel="nofollow" >Topic awaiting preservation: Read txt/ascii with JScript?\

 
Author Thread
smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 02-03-2004 18:19

Hi guys,

I was just wondering whether it is possible to parse css files with JScript as if the css file was just a plain ascii text file?

I want to do this because the standard stylesheet parsing functions in JScript and Javascript will skip any css values IE doesn't understand (replaces them with 'UNKNOWN') - I don't want it to do this - I want to read the whole file as plain text. I'm pretty sure javascript couldn't do it, but I know there are some extra JScript functions that allow stuff like this so I'm hoping that there will be something can do exactly this.

Thanks guys,

Jon

<A HREF="http://www.cryokinesis.co.uk" TARGET=_blank>visit

Cameron
Bipolar (III) Inmate

From: Brisbane
Insane since: Jan 2003

posted posted 02-03-2004 20:12

AFAIK, there is no way you can read data from a file with Javascript unless you load a text file into an iframe then use innerHTML() to get at it.

Might have some more luck with JScript, but I know noffin about that. Sorry.

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 02-03-2004 23:51

Not with javascript - I know there is no way with javascript.

But JScript is a whole different kettly of fish - it has many proprietry and advanced functions that javascript doesn't have and since I only need it to work with IE it's perfect.

Locally JScript can be used to read any ascii based format with something like this:

<script>
var fso, ts, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
ts = fso.OpenTextFile("styles.css", 1);
s = ts.ReadAll();
document.write(s);
</script>

But firstly it pops up an IE warning prompt and then a antivirus security box - it doesn't work however from files on a server - although it can work fine as a complete serverside solution but I can't be doing that.

The prompt problem is because of the ActiveX, so I'm wondering if there is another way to do it with JScript.

Thanks anyway tho,

Jon

<A HREF="http://www.cryokinesis.co.uk" TARGET=_blank>visit

Scott
Bipolar (III) Inmate

From: schillmania.com
Insane since: Jul 2002

posted posted 02-04-2004 05:35

You may be able to load and parse it using an xmlHTTP object (via the .innerHTML property perhaps.)

amikael
Bipolar (III) Inmate

From: övik
Insane since: Dec 2002

posted posted 02-04-2004 16:50

You can infact read data from a textfile using jscript, if that file is a js-file.
It's not much of a bother saving information as objects in a js-file.
- What's wrong with you people anyway??

(^-^)b

Clay
Nervous Wreck (II) Inmate

From: Utreg, NL
Insane since: Nov 2002

posted posted 02-04-2004 20:31

You can use a built in IE behavior, the "download" behavior. For instance, try this:

code:
var sheet, links = document.getElementsByTagName('link');
for(var i=0; i<links.length; i++) {
sheet = links[i];
// if( ) { // possibly some checks here...
sheet.addBehavior('#default#download');
sheet.startDownload(sheet.href, parseCSSText);
// }
}

function parseCSSText(css) {
alert(css); // jay!
}



Then you'll have to filter everything with heaps of regular expressions you're entering a "world of pain", so to speak. :P but it's a fun challenge.

peterned

wrayal
Bipolar (III) Inmate

From: Cranleigh, Surrey, England
Insane since: May 2003

posted posted 02-08-2004 14:18

Cameron, how do you do that. Do you simply make an Iframe, and then do
alert(document.getElementById("myIframe").innerHTML)
on it? I've tried that, and other functions such as alert(document.getElementById("myIframe").src) work, but his simply returns nothing. Any ideas?

Wrayal

EDIT: Sorry, found the problem: should be
alert(myIframe.document.body.innerHTML)

Go to kimber-ja.demon.co.uk and click on the link to the raytracer!

[This message has been edited by wrayal (edited 02-08-2004).]

[This message has been edited by wrayal (edited 02-08-2004).]

« BackwardsOnwards »

Show Forum Drop Down Menu