Javascript

Ruroni

Senior member
Sep 9, 2002
216
0
71
I have 3 frames One is navigation frame, another frame (called source) where I have a <textarea> and then I have a content frame.

The navigation frame has a function to display source code into textarea in "source.htm".

function displayCode()
{
var sSource = "<html>" + parent.Content.document.getElementsByTagName('HTML')[0].innerHTML + "</html>";
parent.source.sourceCode.value = sSource;
}


which can write the source code of the content frame into the <TEXTAREA> of the left column frame (source). This works wonderfully when loading the Local content, but if the content frame loads an external page, the source code button doesn't work anymore.

So: parent.Content.document.body.outerHTML gets me the source code for Content; the question is how can I make it to where "Content" can be any page I visit? (I tried inserting Google in place of Content, (parent.Google.document.body.outerHTML Since Google is Google's title) and visited content in the display Pane, that didn't work)

I figured maybe somehow getURL (or some kind of function or some trick that could be used across platforms ) into a variable on the navigation? But how to get it form the "Content" frame, into the navigation frame?

Anyone, help?

Thanks in Advances
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
You can't. JavaScript, by design, does not allow cross-domain scripting. Your code can only access the DOM of another page if that page is in the same domain. This is a necessary security measure; without it, you could easily hijack JavaScript on other people's websites.
 

Ruroni

Senior member
Sep 9, 2002
216
0
71
Thanks for the reply, much appreciated.

I'm not sure I understand the explanation; I got the "you can't" aspect of it. (I think I get what you mean when you say cross-domain as in going from google.com to yahoo.com ) But I don't see what's the difference between me displaying the source in a <TEXTAREA> inside a frame (from another frame), and displaying a browser's default view-source in notepad.

I believe there are some sites that don't let you viewi-source, but in those cases, I would imagine they could have the fucntion fail.

I'm not trying to argue, like I got some kind of leg to stand on, cause 1) I obviously don't know a whole lot of nothing and 2) any way I toss it and dice it I can't. But I am trying to understand, and if You can explain or point me in the right direction to develop understanding, I'd appreciate it very much.

Thanks again.