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

IFRAME, view-source: for a page not loaded

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

TIA
Pete
Jul 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Pete Wason wrote:
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).
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.
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?


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/

Jul 20 '05 #2

P: n/a
Ivo
"Randy Webb" <hi************@aol.com> wrote in message
news:t_********************@comcast.com...
Pete Wason wrote:
I tried doing this in the "HTML" click:

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


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.
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?


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.


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
Jul 20 '05 #3

P: n/a
Ivo wrote:
"Randy Webb" <hi************@aol.com> wrote in message
news:t_********************@comcast.com...
Pete Wason wrote:
I tried doing this in the "HTML" click:

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


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.

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?


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.

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


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.location = "view-source:" + document.location.href;

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

Pete

Jul 20 '05 #4

P: n/a
Ivo
"Pete Wason" <ro***@hynoom.com> wrote in message
news:10*************@corp.supernews.com...
Ivo wrote:
"Randy Webb" <hi************@aol.com> wrote in message
news:t_********************@comcast.com...

Whenever I view-source:http://etc. I get the source
presented in Notepad, no matter how many windows, frames and iframes I have open.
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.location = "view-source:" + document.location.href;

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

Pete


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
Jul 20 '05 #5

P: n/a
Ivo wrote:
"Randy Webb" <hi************@aol.com> wrote in message
news:t_********************@comcast.com...
Pete Wason wrote:
I tried doing this in the "HTML" click:

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

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.

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?


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.

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??


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 HTTPRequestObject 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.
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.


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

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

Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.