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.location?[/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.javascript FAQ -
http://jibbering.com/faq/