/    Sign up×
Community /Pin to ProfileBookmark

Grab URL of a Frame ?

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?

Any help or insight would be greatly appreciated.

to post a comment
PHP

14 Comments(s)

Copy linkTweet thisAlerts:
@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.
Copy linkTweet thisAlerts:
@phantom6authorNov 22.2006 — I figured as such....already asked in the javascript forum though and cant get anything that works. Thanks though.
Copy linkTweet thisAlerts:
@so_is_thisNov 22.2006 — If that other frame's url is in the same domain as the executing script, then the following works:

JavaScript:var url = top.frames["mainFrame"].location.href;
Copy linkTweet thisAlerts:
@phantom6authorNov 22.2006 — ok I'lll give it a try.......Thanks again.
Copy linkTweet thisAlerts:
@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>&lt;a href="JavaScript:someFunction('whatever.html');"&gt;Link&lt;/a&gt;


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.
Copy linkTweet thisAlerts:
@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.

What do you think?
Copy linkTweet thisAlerts:
@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.
Copy linkTweet thisAlerts:
@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.
Copy linkTweet thisAlerts:
@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.
Copy linkTweet thisAlerts:
@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.
Copy linkTweet thisAlerts:
@hyperliskNov 22.2006 — Then make the PHP also generate JavaScript that changes the Report link.
Copy linkTweet thisAlerts:
@phantom6authorNov 22.2006 — Right I need to display it only if the user actually has clicked and loaded the new frame.

I gotta figure that out somehow........I guess.
Copy linkTweet thisAlerts:
@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!)

netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');

But those weren't desirable way back then (~circa 1999/2000) and it's even less desirable now. I don't even know what it would require today!
Copy linkTweet thisAlerts:
@phantom6authorNov 22.2006 — So I think what I need is....

if (this link is clicked){

generate a report link;

}

just have to figure out how to do that.
×

Success!

Help @phantom6 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...