accessing bare json from iframe

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pgnPoster

    accessing bare json from iframe

    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

  • Martin Honnen

    #2
    Re: accessing bare json from iframe



    pgnPoster wrote:
    [color=blue]
    > 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"
    > }
    > }[/color]

    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
    frameOrWinObjec t.document.body .innerHTML
    e.g. if you have a document containing
    <iframe name="sourceFra me" src="file.txt"> </frame>
    then trying
    var iframe, iDoc;
    if ((iframe = window.frames.s ourceFrame) &&
    (iDoc = iframe.document ) &&
    iDoc.body)
    {
    var source = iDoc.body.inner HTML;
    }
    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

    Comment

    • pgnPoster

      #3
      Re: accessing bare json from iframe

      Martin Honnen wrote:[color=blue]
      >
      > 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
      > frameOrWinObjec t.document.body .innerHTML
      > e.g. if you have a document containing
      > <iframe name="sourceFra me" src="file.txt"> </frame>
      > then trying
      > var iframe, iDoc;
      > if ((iframe = window.frames.s ourceFrame) &&
      > (iDoc = iframe.document ) &&
      > iDoc.body)
      > {
      > var source = iDoc.body.inner HTML;
      > }
      > is one way. But there is no DOM specified for text/plain documents, not
      > sure how good browser support for that is.[/color]

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

      Comment

      Working...