I have a page that consists of two frames.The lower frame has a name, “mainFrame”. Is there a way to grab the URL of the lower frame (mainFrame) and store it in a variable?
@so_is_thisNov 22.2006 — #Not with PHP. JavaScript is the name of the game there -- but, even then, only if that other frame's url is in the same domain as the executing script.
@coppocksNov 22.2006 — #As long as the page loaded in the mainFrame is the same URL as the frameset...
JavaScript <i> </i> var mfloc = parent.mainFrame.location.href;
BUT... if your page changes in the mainFrame, then the top frame won't pick it up until it changes/refreshes.
What you could do, assuming you code all the links... is generate a 3rd frame or hidden frame/iframe... and every page link thats loaded in the mainFrame gets coded with a function that does 2 things... First, change the main frame, and then refresh the hidden frame to detect what was newly loaded in the mainFrame.
Example Link <i> </i><a href="JavaScript:someFunction('whatever.html');">Link</a>
And the function <i> </i> function someFunction(url) { parent.mainFrame.location.href = url; parent.hiddenFrame.location.reload(); }
Probably more than you are looking for. But you could also use PHP in the hidden frame to do info gathering or whatever if that's what you need.
@phantom6authorNov 22.2006 — #Well I really do thank you guys for the help but I don't think it is going to work.
I realize now that since my script opens the frame but the frame is another site that is framed is the reason why I can't get the URL data.
I have a script that opens sites contained in a mysql database ....when it opens them they are framed in the lower frame. I was trying to put code in the top frame to get the URL of the site in the lower frame so I could make a link to "report" an offensive site.
I think as was said earlier, that I can't get that data because it is actually on a different domain (even though my php script just framed it). That is the only reason I can think of that my attempts have failed.
@hyperliskNov 22.2006 — #Well if you get the link from the database, you just just do:
[code=php] echo '<a href="report_abuse.php?site_id='.$row['id'].'">Report Abuse</a>'; [/code] Assuming you get the id from the database, and have it in the $row variable.
@phantom6authorNov 22.2006 — #Right and that is how it is supposed to work. However, I created a link so that when you click it in the top frame you can randomly traverse the sites located in the database.....within the lower frame.......now when I try to "Report" it ends up reporting the original site that the two frames were opened with not the current random site that is in the lower. So I am trying to hack a way to dynamically get whatever the URL is in the bottom frame. Does that make sense?
I can Pm you the site details if it doesn't so you can see.
@hyperliskNov 22.2006 — #Well, is it JavaScript that picks the random site? Or a PHP page? Because if it's JavaScript, you can create a separate array holding the ID values, and then edit the URL of the Report link.
@phantom6authorNov 22.2006 — #No the random site link is generated with PHP. PHP grabs the random site from the database. and puts it into a link to click on.
@coppocksNov 22.2006 — #That is correct, unless you code the URLS as I showed previously. Then the topframe reporting URL could be created by reloading it when a link is clicked.
This goes back a ways... IE used to not do it w/out a signed ActiveX control and Netscape required a "trusted script" to call something like ... (from memory!)