accessing bare json from iframe

P

pgnPoster

I am having the dickens of a time figuring this out. I've been
googling high and low, but all the examples I find involve the iframe's
src containing some HTML albeit minimal. I just want it to contain
"bare" json such as:

{
"fields": {
"firstName",
"middleInitial",
"lastName"
}
}

If I set the src attribute of an iframe to a file that contains nothing
but the above, using the DOM, how do I access the above as text? I
presume that on the page that defines the iframe (which will be
"hidden" by the way), that I will need to specify div tags. Do these
go outside the iframe tags or inside? Lots of questions as you can
see. All help greatly appreciated, including pointing me to other
URLS. Though as I say I've googled extensively and have yet to find an
example where the iframe's src was "bare" text.

Thanks in advance
 
M

Martin Honnen

pgnPoster said:
I've been
googling high and low, but all the examples I find involve the iframe's
src containing some HTML albeit minimal. I just want it to contain
"bare" json such as:

{
"fields": {
"firstName",
"middleInitial",
"lastName"
}
}

Well what exactly do you want the iframe to contain, plain text with a
JavaScript expression (although you should put that in parentheses to be
one)?
Then serve that file as text/plain.
Some browsers allow you to access the contents of a plain text file in a
window or frame as
frameOrWinObject.document.body.innerHTML
e.g. if you have a document containing
<iframe name="sourceFrame" src="file.txt"></frame>
then trying
var iframe, iDoc;
if ((iframe = window.frames.sourceFrame) &&
(iDoc = iframe.document) &&
iDoc.body)
{
var source = iDoc.body.innerHTML;
}
is one way. But there is no DOM specified for text/plain documents, not
sure how good browser support for that is. Any Konqueror or Safari users
out there who could say?
 
P

pgnPoster

Martin said:
Well what exactly do you want the iframe to contain, plain text with a
JavaScript expression (although you should put that in parentheses to be
one)?
Then serve that file as text/plain.
Some browsers allow you to access the contents of a plain text file in a
window or frame as
frameOrWinObject.document.body.innerHTML
e.g. if you have a document containing
<iframe name="sourceFrame" src="file.txt"></frame>
then trying
var iframe, iDoc;
if ((iframe = window.frames.sourceFrame) &&
(iDoc = iframe.document) &&
iDoc.body)
{
var source = iDoc.body.innerHTML;
}
is one way. But there is no DOM specified for text/plain documents, not
sure how good browser support for that is.

Thanks! Worked like a charm in IE6 & FF1.5
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top