Click to See Complete Forum and Search --> : Access to document.links from another frame


-kde-
11-15-2003, 09:06 PM
I have such frame structure:

<frameset rows="0,100%" border=0>
<frame src="1.html" name="frame1">
<frame src="empty.html" name="loc">
</frameset>

Page 1.html contains this code:

<script language="JavaScript">
hehe = setTimeout("top.frames['loc'].location = 'http://somesite.com/somepage.html'", 1000);
hehe = setTimeout("mylink = top.frames['loc'].document.links[0]", 5000);
</script>

I need to get the first link from the page from the other site, which is opened in the lower frame. Obviously I need to do it from the upper frame. But my script shows error: "Access denied".
What I should do?

Pittimann
11-16-2003, 03:01 AM
Hi -kde-!

Try this in your 1.html:

<script language="JavaScript">
hehe = setTimeout("top.frames['loc'].location = 'http://somesite.com/somepage.html'", 1000);
hehe = setTimeout("top.frames['loc'].location = top.frames['loc'].document.links[0]", 5000);
</script>


In MSIE6 I tested your original code. Of course the second settimeout of your code had no effect (you just declared a variable, without working with it), but I didn't get any error.

I was too lazy to test the code above in more Browsers, just Netscape 4.7 and MSIE6. It works perfectly in both of them.

Cheers - Pit

-kde-
11-16-2003, 05:31 AM
Thanks, Pit, but you must have tested it with your local files. But if you try to open some URL from the other site in the lower frame, you'll get my error. Try to test your script on one site, and open page from another...

Pittimann
11-16-2003, 05:41 AM
Hi -kde-!

You're right - I tested it locally.

After I received the mail informing me about your new post, I uploaded the files and it works as I told you! Maybe you didn't realize that I changed your code - try it and you will see...

Cheers - Pit

-kde-
11-16-2003, 07:13 AM
After I received the mail informing me about your new post, I uploaded the files and it works as I told you! Maybe you didn't realize that I changed your code - try it and you will see...

Well, I give you expample of my code:

index.html:

<html>
<frameset rows="0,100%" border=2>
<frame src="1.html" name="frame1">
<frame src="empty.html" name="loc">
</frameset>
</html>


1.html:

<html><head><title></title>
<script language="JavaScript">
function StartSearch() {
hehe = setTimeout("top.frames['loc'].location = 'http://www.microsoft.com/windowsserversystem/management/default.mspx'", 5000);
hehe = setTimeout("top.frames['loc'].location = top.frames['loc'].document.links[0]", 10000);
}
</script>
</head>
<body onLoad="StartSearch();">
</body></html>


Whats's wrong?
I have the same error and second timeout doesn't occur...

Charles
11-16-2003, 07:26 AM
Originally posted by -kde-
Whats's wrong?1) Your HTML is invalid.

2) The "language" attribute was depricated in favor of "type" back in 1997.

3) Function and method names should start with a lower case letter.

4) You shouldn't over write the object returned by the first setTimeout with the object returned by the second. Though, in this case there is no reason to assign either to a variable.

5) For security reasons JavaScript will not let you play around with other people's pages.

-kde-
11-16-2003, 08:07 AM
1) Your HTML is invalid.
If I've missed <head>, <title>, title or something of this kind it doesn't mean that browser would interpret my HTML in a wrong way. Browsers bacame more "clever" since IE 3.0 ... Besides, I don't say that it is my full-version code...
3) Function and method names should start with a lower case letter.
Function names are case-sensitive, but it doesn't matter that we should start them with a lower case IMHO...
5) For security reasons JavaScript will not let you play around with other people's pages.
So, it's the core of my question. As I understand JavaScript can't access ANY objects on other people's pages, even in read-only mode? As I thought Java works localy on client machine with the data parsed by browser and cached with it, so it is no matter from what source this data have been recieved... Am I wrong?

Charles
11-16-2003, 08:23 AM
Originally posted by -kde-
If I've missed <head>, <title>, title or something of this kind it doesn't mean that browser would interpret my HTML in a wrong way. Browsers bacame more "clever" since IE 3.0 ... Besides, I don't say that it is my full-version code...

The HEAD start and close tags are optional. I see now why your HTML is invalid and you've omitted the necessary DOCTYPE and content type.

Function names are case-sensitive, but it doesn't matter that we should start them with a lower case IMHO...

You asked what was wrong, not just what was fatally wrong. JavaScript follows the Java Naming Conventions (http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html).

So, it's the core of my question. As I understand JavaScript can't access ANY objects on other people's pages, even in read-only mode? As I thought Java works localy on client machine with the data parsed by browser and cached with it, so it is no matter from what source this data have been recieved... Am I wrong?

You are not allowed to play around with other people's pages.

Pittimann
11-16-2003, 08:30 AM
Hi once again!

The code I posted before works (despite of - greetz to Charles - invalid HTML, Upper Case Function Name, language instead of type, overwriting the setTimeout object). As far as security is concerned:

I tested it with a frameless page on my webspace. It surprised me that it doesn't work on sites somewhere else (even if frameless as well). I got the same "access denied"!

Question to -kde-:

Am I right, that you want a certain link to be "opened" and not just the first one on the page (whatever it is...)?? In your example, I understand, that you want "http://www.microsoft.com/windowsserversystem/management/default.mspx" to be displayed for a number of seconds and then "http://www.microsoft.com/windowsserversystem/default.mspx", which is the first link there.

If my assumption s correct, why don't you do it this way:

<script language="JavaScript">
hehe = setTimeout("top.frames['loc'].location = 'http://www.microsoft.com/windowsserversystem/management/default.mspx'", 1000);
hehe = setTimeout("top.frames['loc'].location = 'http://www.microsoft.com/windowsserversystem/default.mspx'", 5000);
</script>

No link-stuff which causes the error. Like that it worked fine...

Cheers - Pit

-kde-
11-16-2003, 09:13 AM
2 Pittimann:
Quite the opposite... I need to open some appointed page over the WWW then find out the first (may be not just first) link, parse some parameter form it into variable to work with it. But the problem occures on the step where I try to use document.links collection...

2 Charles:
I just need to get some "Id" form the page (from links or form's fields) on the other site via Java. Are there ANY ways to do it?

Charles
11-16-2003, 12:38 PM
Originally posted by -kde-
Are there ANY ways to do it? Do it server side. In Perl it would be only a few lines of code if you were to eploy the HTML::LinkExtor (http://www.perldoc.com/perl5.8.0/lib/HTML/LinkExtor.html) module.

Pittimann
11-16-2003, 01:20 PM
Hi -kbd-, hi Charles!

Server side will be easy of course. If you - kbd - like, I'll post a very small php-script (if it is allowed to post php-code to the js forum :rolleyes: ) tomorrow. Tonight I have something different to do than scripting.

If you have some basic php knowledge it will be easy for you to check tags other than <a> as well by changing the script...

Have a good start into the new week - Pit

-kde-
11-16-2003, 04:50 PM
I know, how to do it via PHP by means of socket connection, but I can't use neither PHP nor Perl at my hosting...
Anyway thanks, everybody!