PDA

View Full Version : Targeting links using javascript


Greg
06-30-03, 04:05 PM
I have an iFrame that contains a listing of records from a database. Instead of making the text in each row a link (using a link tag), I am using javascript to make the whole row a link. So, when you double-click the row it'll open a particular link.

----------------
<tr bgcolor="CCCFD6"
onmouseover="this.style.backgroundColor='#DCDEF1'; this.style.cursor = 'hand';"
onmouseout="this.style.backgroundColor='#CCCFD6';"
ondblclick="location.href='#';">
----------------

Right now all the links open in the iFrame, when I want them to open in the main window. I have done a lot of research and I can't find the right code to make the links not open in the iFrame. If I used regular <a> tag it would be simple to set the target="_top". What I have tried is: location.target='_top';, but it doesn't work.

Any input would be a great help... thanks.

Ryan
06-30-03, 04:20 PM
As you may know, when you use an iFrame, it's a page that's nested into another page. So, when you say, "_top" it's going to do it in the iFrame. If I understood you correctly, then you want a link that is clicked in the iFrame to open in the main page. When you add the link, try putting the actual address of the page. I'm not a JavaScript expert so I could be entirely wrong, but from what I understand this should work OK.

Greg
06-30-03, 04:26 PM
Actually a link in an iFrame with target set to "_top" will break out and open in the main window. I just don't know the javascript code to set the link target.

Ryan
06-30-03, 05:01 PM
Ahh, I thought it would stay in the same frame. I guess it's been longer than I thought since I've done JavaScript. :(

Greg
06-30-03, 05:06 PM
:-)

I actually just figured it out. I used: "parent.location.href" instead of "location.href" and that did exactly what I wanted.

Thanks Ryan.. I appreciated your input. :-)