PDA

View Full Version : target in javascript



toe_head2001
01-05-2006, 10:56 PM
I need to change this:
<A HREF="page.html" target="name of frame">do it</A>
to something like this:
onload="window.location='page.html';"

how do I do the target in js?

thanks

jscheuer1
01-06-2006, 06:21 AM
It can depend upon what page you are putting this code on but, in many cases, this will do the trick:


<body onload="parent.name of frame.location='page.html'">

or as part of a script:


onload=function(){
parent.name of frame.location='page.html';
}

toe_head2001
01-09-2006, 03:09 AM
What about this:

<BUTTON onclick="window.location=search.cat.options[search.cat.selectedIndex].value + search.user.value;">Search</BUTTON>

What would I do if I wanted the target to be _blank?

jscheuer1
01-09-2006, 05:37 AM
That's a special case, simulating target="_blank". To do that in javascript one needs to open a new window, a pop up. Generally this is fine for a click event but, some aggressive pop up blockers will even stop that. Be that as it may, here is the code:


<input type="button" onclick="window.open(search.cat.options[search.cat.selectedindex].value + search.user.value);" value="Search">

Twey
01-09-2006, 04:23 PM
Generally this is fine for a click event but, some aggressive pop up blockers will even stop that.They shouldn't. If a popup blocker blocks window.open() calls contained within an onclick event, said popup blocker is broken.

jscheuer1
01-09-2006, 07:23 PM
They shouldn't. If a popup blocker blocks window.open() calls contained within an onclick event, said popup blocker is broken.

Not broken, no. Agressive. They (some pop up blockers) can be set to specifically be that aggressive.

Twey
01-09-2006, 07:42 PM
Disabling useful and often necessary functionality initiated (almost certainly knowingly) by the user is, to my way of thinking, destructive behaviour.

mwinter
01-09-2006, 07:54 PM
I agree with John, though it's rather more fact that than opinion. Both built-in (IE and Opera) and third-party (especially proxy) blockers allow the user to prevent the appearance of all pop-ups.


Disabling useful and often necessary functionality initiated (almost certainly knowingly) by the user is, to my way of thinking, destructive behaviour.How so, if the user disabled all pop-ups?

Mike

jscheuer1
01-09-2006, 08:33 PM
Thanks, Mike. There is always this (and similar, some even more egregious) situation:


<a href="http://www.google.com" onclick="window.open('obnoxious_ad.htm');return true;">Google</a>

I can see why some would, and have been tempted myself at times to, disable all pop ups because of designers who take advantage of this loophole.