By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,650 Members | 753 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,650 IT Pros & Developers. It's quick & easy.

accessing bare json from iframe

P: n/a
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

Jan 30 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a


pgnPoster wrote:
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?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jan 30 '06 #2

P: n/a
Martin Honnen wrote:

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

Jan 30 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.