IFRAME, view-source: for a page not loaded

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

    IFRAME, view-source: for a page not loaded

    Hiall!

    I have a demo viewer page for javascript stuff that has three buttons "DEMO"
    "HTML" and "JSCR", and an IFRAME called 'viewer'.

    Initially, the IFRAME gets loaded with the actual demo page, ie.,

    viewer.location = dName + '.html';

    where dName is the filename of the demo without extension.

    Clicking on "HTML" replaces the IFRAME contents like this:

    viewer.location = "view-source:" + viewer.location .href;

    And Clicking on "JSCR" replaces the IFRAME contents like this:

    viewer.location = dName + '.js';

    These all work OK by themselves - at least at first. The problem comes when I
    Click "JSCR" to display the appropriate .js file, and then click "HTML" to go
    back to the source of the HTML file: I just get the .js file again (and it's
    fairly obvious why).

    I tried doing this in the "HTML" click:

    viewer.location = dName + '.html';
    viewer.location = "view-source:" + viewer.location .href;

    attempting to reload the demo page before showing its source, but this doesn't
    work very well - I have to click "HTML" 2 or 3 times to get the source to
    appear (because, I think, both these lines need the function to return before
    anything really happens visually).

    In a nutshell:

    How I can view (in an IFRAME) the source of an html page which is not the
    IFRAME's current document.locati on?

    TIA


    Pete


  • Randy Webb

    #2
    Re: IFRAME, view-source: for a page not loaded

    Pete Wason wrote:[color=blue]
    > Hiall!
    >
    > I have a demo viewer page for javascript stuff that has three buttons
    > "DEMO" "HTML" and "JSCR", and an IFRAME called 'viewer'.
    >
    > Initially, the IFRAME gets loaded with the actual demo page, ie.,
    >
    > viewer.location = dName + '.html';
    >
    > where dName is the filename of the demo without extension.
    >
    > Clicking on "HTML" replaces the IFRAME contents like this:
    >
    > viewer.location = "view-source:" + viewer.location .href;
    >
    > And Clicking on "JSCR" replaces the IFRAME contents like this:
    >
    > viewer.location = dName + '.js';
    >
    > These all work OK by themselves - at least at first. The problem comes
    > when I Click "JSCR" to display the appropriate .js file, and then click
    > "HTML" to go back to the source of the HTML file: I just get the .js
    > file again (and it's fairly obvious why).
    >
    > I tried doing this in the "HTML" click:
    >
    > viewer.location = dName + '.html';
    > viewer.location = "view-source:" + viewer.location .href;
    >
    > attempting to reload the demo page before showing its source, but this
    > doesn't work very well - I have to click "HTML" 2 or 3 times to get the
    > source to appear (because, I think, both these lines need the function
    > to return before anything really happens visually).[/color]

    You have a timing issue. When you set its location to dName + '.html';,
    and then set it to view-source, it hasnt had time to load the page so
    you see what was already there - the .js source. Look into the
    readyState property of the IFrame. Then, when its loaded, show its source.
    [color=blue]
    > In a nutshell:
    >
    > How I can view (in an IFRAME) the source of an html page which is not
    > the IFRAME's current document.locati on?[/color]

    Another, maybe better, solution would be to use 2 IFrames, 1 is hidden.
    IFrame1 would be hidden and contain the HTML file.

    When you clicked, instead of setting it to the view-source of its own
    location.href, you set it to display view-source: of the hidden frames
    href property.

    Then, to display the .js, you set it to the dName + '.js';

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javas cript FAQ - http://jibbering.com/faq/

    Comment

    • Ivo

      #3
      Re: IFRAME, view-source: for a page not loaded

      "Randy Webb" <hikksnotathome @aol.com> wrote in message
      news:t_WdneelnM 8g96DdRVn-jQ@comcast.com. ..[color=blue]
      > Pete Wason wrote:[color=green]
      > > I tried doing this in the "HTML" click:
      > >
      > > viewer.location = dName + '.html';
      > > viewer.location = "view-source:" + viewer.location .href;
      > >[/color]
      >
      > You have a timing issue. When you set its location to dName + '.html';,
      > and then set it to view-source, it hasnt had time to load the page so
      > you see what was already there - the .js source. Look into the
      > readyState property of the IFrame. Then, when its loaded, show its source.
      >[color=green]
      > > In a nutshell:
      > >
      > > How I can view (in an IFRAME) the source of an html page which is not
      > > the IFRAME's current document.locati on?[/color]
      >
      > Another, maybe better, solution would be to use 2 IFrames, 1 is hidden.
      > IFrame1 would be hidden and contain the HTML file.
      >
      > When you clicked, instead of setting it to the view-source of its own
      > location.href, you set it to display view-source: of the hidden frames
      > href property.
      >[/color]

      I don't believe it. Whenever I view-source:http://etc. I get the source
      presented in Notepad, no matter how many windows, frames and iframes I have
      open. How do you get it to display in the browser??
      Also, the page that I 'm viewing the source does not need to be loaded in
      any browser (though it helps speed-wise) as far as I am aware.
      Ivo


      Comment

      • Pete Wason

        #4
        Re: IFRAME, view-source: for a page not loaded

        Ivo wrote:[color=blue]
        > "Randy Webb" <hikksnotathome @aol.com> wrote in message
        > news:t_WdneelnM 8g96DdRVn-jQ@comcast.com. ..
        >[color=green]
        >>Pete Wason wrote:
        >>[color=darkred]
        >>>I tried doing this in the "HTML" click:
        >>>
        >>> viewer.location = dName + '.html';
        >>> viewer.location = "view-source:" + viewer.location .href;
        >>>[/color]
        >>
        >>You have a timing issue. When you set its location to dName + '.html';,
        >>and then set it to view-source, it hasnt had time to load the page so
        >>you see what was already there - the .js source. Look into the
        >>readyState property of the IFrame. Then, when its loaded, show its source.
        >>
        >>[color=darkred]
        >>>In a nutshell:
        >>>
        >>>How I can view (in an IFRAME) the source of an html page which is not
        >>>the IFRAME's current document.locati on?[/color]
        >>
        >>Another, maybe better, solution would be to use 2 IFrames, 1 is hidden.
        >>IFrame1 would be hidden and contain the HTML file.
        >>
        >>When you clicked, instead of setting it to the view-source of its own
        >>location.href , you set it to display view-source: of the hidden frames
        >>href property.
        >>[/color]
        >
        >
        > I don't believe it. Whenever I view-source:http://etc. I get the source
        > presented in Notepad, no matter how many windows, frames and iframes I have
        > open. How do you get it to display in the browser??
        > Also, the page that I 'm viewing the source does not need to be loaded in
        > any browser (though it helps speed-wise) as far as I am aware.
        > Ivo
        >
        >[/color]

        What browser are you using? Netscape 7.1 here... standard Mozilla behaviour,
        which is to say, standards-compliant behaviour. I never use IE unless a page
        forces me to (bad page! no biscuit!), so I don't know (or, in general, care)
        how it interprets view-source:

        document.locati on = "view-source:" + document.locati on.href;

        Seems to work fine, as long as the page you want to see the source of is
        already loaded.

        Pete

        Comment

        • Ivo

          #5
          Re: IFRAME, view-source: for a page not loaded

          "Pete Wason" <rogue@hynoom.c om> wrote in message
          news:103ul26m3a 8mt00@corp.supe rnews.com...[color=blue]
          > Ivo wrote:[color=green]
          > > "Randy Webb" <hikksnotathome @aol.com> wrote in message
          > > news:t_WdneelnM 8g96DdRVn-jQ@comcast.com. ..
          > >
          > > Whenever I view-source:http://etc. I get the source
          > > presented in Notepad, no matter how many windows, frames and iframes I[/color][/color]
          have[color=blue][color=green]
          > > open.[/color][/color]
          [color=blue]
          > What browser are you using? Netscape 7.1 here... standard Mozilla[/color]
          behaviour,[color=blue]
          > which is to say, standards-compliant behaviour. I never use IE unless a[/color]
          page[color=blue]
          > forces me to (bad page! no biscuit!), so I don't know (or, in general,[/color]
          care)[color=blue]
          > how it interprets view-source:
          >
          > document.locati on = "view-source:" + document.locati on.href;
          >
          > Seems to work fine, as long as the page you want to see the source of is
          > already loaded.
          >
          > Pete[/color]

          I just typed in my IE addressbar

          view-source:http://www.nytimes.com/

          and up popped the code. Since I have not been there in a while and it
          contains today's news, I can be sure it isn't a cached copy.
          Fwiw,
          Ivo


          Comment

          • Randy Webb

            #6
            Re: IFRAME, view-source: for a page not loaded

            Ivo wrote:
            [color=blue]
            > "Randy Webb" <hikksnotathome @aol.com> wrote in message
            > news:t_WdneelnM 8g96DdRVn-jQ@comcast.com. ..
            >[color=green]
            >>Pete Wason wrote:
            >>[color=darkred]
            >>>I tried doing this in the "HTML" click:
            >>>
            >>> viewer.location = dName + '.html';
            >>> viewer.location = "view-source:" + viewer.location .href;
            >>>[/color]
            >>
            >>You have a timing issue. When you set its location to dName + '.html';,
            >>and then set it to view-source, it hasnt had time to load the page so
            >>you see what was already there - the .js source. Look into the
            >>readyState property of the IFrame. Then, when its loaded, show its source.
            >>
            >>[color=darkred]
            >>>In a nutshell:
            >>>
            >>>How I can view (in an IFRAME) the source of an html page which is not
            >>>the IFRAME's current document.locati on?[/color]
            >>
            >>Another, maybe better, solution would be to use 2 IFrames, 1 is hidden.
            >>IFrame1 would be hidden and contain the HTML file.
            >>
            >>When you clicked, instead of setting it to the view-source of its own
            >>location.href , you set it to display view-source: of the hidden frames
            >>href property.
            >>[/color]
            >
            >
            > I don't believe it. Whenever I view-source:http://etc. I get the source
            > presented in Notepad, no matter how many windows, frames and iframes I have
            > open. How do you get it to display in the browser??[/color]

            Can I scratch my head a few more days and try to remember what I screwed
            up badly to make it work the first time? Of course, you are right with
            regards to view-source.

            Personally, if I wanted to show the source of the page in an IFrame,
            with IE, I would use an HTTPRequestObje ct to load it and then display it
            via IE's innerText property. Probably using a div instead of IFrame though.

            A better approach, all around, would be to submit to the server and let
            the server get it, return it as plain text and display it though.
            [color=blue]
            > Also, the page that I 'm viewing the source does not need to be loaded in
            > any browser (though it helps speed-wise) as far as I am aware.[/color]

            No, it doesn't have to be loaded in the browser.

            --
            Randy
            Chance Favors The Prepared Mind
            comp.lang.javas cript FAQ - http://jibbering.com/faq/

            Comment

            Working...