/    Sign up×
Community /Pin to ProfileBookmark

Capture HREF while targeting multiple frames

I have a simple application I’m developing that uses three frames:
banner
contents
main

I want links in the content frame to be able to target main with the href value of the link (standard) and also target the banner frame. I also didn’t want to hand code all the links in contents so I decided to use a script to set all of that page’s links’ onclick event to target the banner frame. That all worked fine.

The problem I’m running into is that I want to pass the href value to the banner frame because I want to set up a trail of the links they clicked in the contents frame. Since I was already adding the onclick event, I figured this should be easy by just appending a query string to the URL of the banner’s page, but I hit a snag:

[CODE]function setTop() {
var el = document.getElementsByTagName(‘a’)
for (var i=0;i<el.length;i++)
{
var hrefLink = ‘stats_top1.asp?link=’ + document.links[i].href
el[i].onclick = function() { parent.banner.location.href = hrefLink; };
}
}[/CODE]

The problem is that regardless of which link in the contents frame they click, it passes the href value of the last link on that page. I did some searching and found out why this was happening, but not a work around. Since the frame pages are ASP, I would like to use the QueryString to pass the clicked URL’s href so I have server side options on what to do with it. I have spent the entire day trying to find a suitable workaround, but have nothing.

If you want to look at the frame set I’m working on:

[url]http://www.nyrforum.com/stats.asp[/url]

I may be trying different things when you look at it.

Edit: at the moment, I have it putting the address it thinks you clicked on in an alert (for testing) so you can actually see that it’s passing the last link on the content page.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Sterling_IsfineJul 06.2009 — [CODE]function setTop()
{
var el = document.getElementsByTagName('a')

for (var i=0; i<el.length; i++)
el[i].onclick = function()
{
parent.banner.location.href = 'stats_top1.asp?link=' + this.href;
}

}[/CODE]
Copy linkTweet thisAlerts:
@downtimeauthorJul 06.2009 — [CODE]function setTop()
{
var el = document.getElementsByTagName('a')

for (var i=0; i<el.length; i++)
el[i].onclick = function()
{
parent.banner.location.href = 'stats_top1.asp?link=' + this.href;
}

}[/CODE]
[/QUOTE]


Thanks Sterling, that worked perfectly. I hate when it's that easy and you're just not seeing it. I tried to make it way too difficult.
×

Success!

Help @downtime 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.19,
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,
)...