473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

TIA
Pete
Jul 20 '05 #1
5 7185
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: gsb | last post by:
Is there any way to make the background of an iFrame (object) transparent? The iFrame is in a 'floating' DIV and I want the underlying HTML page to show through as a background. Thanks, gsb
6
by: Phlip | last post by:
JavaScripties: On the HTML side, we load an IFRAME with a blank page: <iframe frameborder="0" marginwidth="0" marginheight="0" scrolling="off" src="about:blank" id="iframe_xml1!format_text"...
2
by: Robert Oschler | last post by:
I have an IFrame whose document is created completely by Javascript code at runtime. The document in the IFrame accesses Javascript functions in the top level document. This works fine most of...
0
by: Kenneth Keeley | last post by:
Hi We have an Iframe that displays the contents of a folder. By default the files are shown as large icons. I would like to change this so that the files display as a list of files (ie small icon...
1
by: mandakini | last post by:
Hello freinds I am working on this url http://72.36.156.243/compbuild.php Here I am using ifram and displaying dynamic value I don't know how to use iframe as array how to assign array and...
0
by: Mike P | last post by:
I am using the tree view IE web control and I need to show different iframes depending upon which node in the tree view has been clicked, and if not have been clicking I don't want any iframe to...
4
Samji
by: Samji | last post by:
Hello everyone. I am trying to write out the contents of a tag in an XML document to an iframe. I can do that successfully with the following code... function constructMsgBody() { //...
4
by: Amuthaangler | last post by:
Hi all, I am currently working with Iframe which holds the JSON response from the server once when the picture gets uploaded successfully. Now I need to parse the JSON response and retrieve...
4
by: R144N | last post by:
Hi Everyone, I've searched variuos forums as much as I could for a similar problem within the time I could and found no helpful solution, I hope someone here can help me out: I have an iFrame...
1
by: John L. | last post by:
How do I invoke the scroll() method of a window object for a scrollable IFRAME element in an HTML document? I am using IE 7.0, and I thought the following would work: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.