View Full Version : Target="_top" not working from within javascript and frames.

06-13-2003, 10:36 PM
The web page uses frames. Within "text frame" is this code:

<script language="Javascript">
function formHandler(chapter)
var GOTO=document.chapter.url.options[document.chapter.url.selectedIndex].value;

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<!-- content (start) -->

<table cellpadding=0 align=center border=0>
<td valign=top>
<p class="bodytext">To download a document,
just select the one you want from the pull-down menu below.

<form name="chapter">
<select name="url" size=5>
<option selected value=" ">Please select chapter . . . </option>
<OPTION VALUE="http://www.xxxxxxx.org/Chapter1.doc" target="_top">Chapter 1</option>
<OPTION VALUE="http://www.xxxxxxx.org/Chapter2.doc" target="_top">Chapter2</option>

etc., etc. etc.

Problem: Despite the target="_top" coding, the content of the imported document is loading into the frame that has the coding text rather than in a new browser page. I am using the same coding multiple places as straight html and they all load as advertised. Only difference here is that the new document is called from within Javascript.

Is there something about Javascript that negates the target="_top" (or target="_parent" -- I tried that, too). I can't find anything about this in multiple Internet searches.

Thanks for the help!

06-14-2003, 04:02 AM
Actually, you need to put the target="top" in the <form> tag, not the <option> tags.


06-14-2003, 05:51 AM
or u can do this:

<Select ... onchange="top.location=this.options[this.selectedIndex].value">
<Option value="123.html?a=b">B</option>
<Option value="345.html?a=c">C</option>

i havent try this example... u can try this and see.
u can think about it if u have different of option value.

06-14-2003, 03:31 PM
Andrew's suggestion didn't work, but Ninja Turtle's solution sure did. Thank's for the help from both:thumbsup:

El Jimi
08-11-2005, 01:45 AM
i recently found this javascript redirect script at the javascript source website(javascript.internet.com (http://javascript.internet.com)).

a few months ago i switched from a free .tk domain to a paid .be domain (.be is for belgium) for my website. i had to pay for the hosting as well, so i ended up with two sites with the same content (actually three, but that's another story). i figure many of the visitors of my site are quite bothered by the fact that they have to click on another link to get access to the info i offer. so that's why i put your redirect script on the site to make things easier for the visitors.

the problem is: the .tk frame parents the frame that is used by the webpages themselves. so when i put a redirect script on the pages, everything works great, except that the .be paid domain is loaded in the frame that's underneath the .tk frame. so whichever link to access whichever page is clicked, the visitor is still surfing on the .tk site.

my question is: could someone please add a line to the script so that the site i paid for is loaded in the parent frame?

FYI: www.alibi-ike.tk (http://www.alibi-ike.tk) - www.alibi-ike.be (http://www.alibi-ike.be). the website is in dutch, and it's the official site of a local cover band called Alibi Ike. my third site is already successfully redirected. it originally resided on the servers of a belgian ISP called scarlet. the url is http://home.scarlet.be/~js006607.

the following script is the javascript code as it's embedded in the html code on my websites (that are redirected):

<SCRIPT language="JavaScript">
<!-- Original: Corey (638@gohip.com ) -->
<!-- Web Site: http://six38.tripod.com -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
var start=new Date();
var counts=5;
function CountDown(){
var now=new Date();
var x=parseInt(counts-(now-start),10);
if(document.form1){document.form1.clock.value = x;}
timerID=setTimeout("CountDown()", 50)
// End -->

<SCRIPT language="JavaScript">

<SCRIPT language="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com --></SCRIPT>
<FORM NAME="form1">Je wordt automatisch doorverbonden in <INPUT type="text" name="clock" size="2" value="5"> seconden.</FORM>

i figure the line of code that i'd really like to see added must be something like this:

top.location.target="_top" or
window.location.target="_top" or
top.location.target="_top" or...

thank you very much in advance!