PDA

View Full Version : How do I insert a target="_top" command



davidjovan
12-14-2005, 12:19 PM
in the "Rollover background-color button" script located here http://dynamicdrive.com/dynamicindex5/button3.htm ........ in the FORM section of the code, where would I put a [ target="top" ] command so that the page opens on a page by itself?



<form onMouseover="change(event, 'yellow')" onMouseout="change(event, 'lime')">
<input type="button" value="Yahoo" class="initial2" onClick="jumpto2('http://yahoo.com [would it go here?]')">
</form>


PS: i am calling the menu from an iframe and I want it to be able to break out of the iframe when the button is clicked.

ddadmin
12-14-2005, 01:18 PM
Sure thing. Simply modify the orginal function jumpto2() inside the code of Step 1 to:



function jumpto2(url, breakout){
if (typeof breakout!=undefined" && breakout=="break")
window.parent.location=url
if (buttontarget=="")
window.location=url
else if (buttontarget=="_new")
window.open(url)
else
parent[buttontarget].location=url
}


Then inside your HTML, you can do things such as:


onClick="jumpto2('http://yahoo.com')" //NO targeting
onClick="jumpto2('http://yahoo.com', 'break')" //break out of frame

davidjovan
12-15-2005, 02:35 AM
Thanks for the quick response. It didn't work at first, but after taking a good look @ your modification, I noticed that a " was missing. Check it out here.



function jumpto2(url, breakout){
if (typeof breakout!="undefined" && breakout=="break")
window.parent.location=url
if (buttontarget=="")
window.location=url
else if (buttontarget=="_new")
window.open(url)
else
parent[buttontarget].location=url
}
//-->


Thanks again for your quick response and help

Capion
02-03-2006, 03:21 PM
isnt it more correct and more compatible to use this:

self.frames[buttontarget].location.href=url

in stead of the

parent[buttontarget].location=url

( which gave me trouble with IE 6.0.2900.2180 ( sp2 ) )
?

Twey
02-03-2006, 04:22 PM
Yes, but they aren't interchangable.
Which of the two you should use depends on where the script is being called from: parent... should be used if being called from within a frame at the same level as the target frame. self... should be used if called from the frameset page, or if using an iframe. You are partly right: parent[buttontarget] would be better expressed as parent.document.getElementById(buttontarget) or parent.document.getElementsByName(buttontarget)[0].