...

View Full Version : Opening link in New Window, with JavaScript



dmk
06-10-2003, 03:37 PM
On our Intranet, I have a series of drop-down menus in Frame 2. Each link opens in Frame 3. A few months ago, I needed to add a menu item to Frame 2 that had to open in a New Window (instead of in Frame 3) and I got some help on that. Now I need to add another menu item that must open in a New Window, but I don't know how to amend the code (please see below) to do that. Thanks.

This shows the code that forces the Expense Report to open in a new window:


<script LANGUAGE="JavaScript">
<!--
function JumpToIt (list)
{
var selection = list.options[list.selectedIndex].value
if (selection != "NewWindow") {
parent.body.location.href = selection
}else{
window.open("http://dk_intranet/FinanceDept/ExpenseRpt.xls","def")
}
list.selectedIndex=0
}


//-->


This is the code of the actual drop-down menu where the Expense Report choice exists:



<form>
<select WIDTH="1" onChange="JumpToIt(this)" size="1" name="Finance" style="font-family: Arial; font-size: 8pt; position: relative; float: left; width: 150">


<option VALUE="http://dk_intranet/link_pg_finance_dept.htm" selected>Finance Department
---&gt;
<option VALUE="http://dk_intranet/FinanceDept/BillCover.pdf">Bill Cover Ltr Instructions</option>
<option VALUE="http://dk_intranet/FinanceDept/Work Assignmt.htm">Billing/Attorney Assignments</option>

<option VALUE="NewWindow">Expense Report</option>


<option VALUE="http://dk_intranet/FinanceDept/GBMileage.pdf">Green Bay Mileage Chart</option>
</select></form>

requestcode
06-10-2003, 06:01 PM
You could try this:
<html>
<head>
<title>Test</title>
<script LANGUAGE="JavaScript">
function JumpToIt (list)
{
var selection = list.options[list.selectedIndex].value.split("|")
if(selection[0]=="frame")
{
parent.main.location.href = selection[1]
}
else
{window.open(selection[1],"def")}
list.selectedIndex=0
}
</script>
</head>
<body>
<form>
<select WIDTH="1" onChange="JumpToIt(this)" size="1" name="Finance" style="font-family: Arial; font-size: 8pt; position: relative; float: left; width: 150">
<option VALUE="frame|http://dk_intranet/link_pg_finance_dept.htm" selected>Finance Department</option>
<option VALUE="frame|http://dk_intranet/FinanceDept/BillCover.pdf">Bill Cover Ltr Instructions</option>
<option VALUE="frame|http://dk_intranet/FinanceDept/Work Assignmt.htm">Billing/Attorney Assignments</option>
<option VALUE="NewWindow|http://dk_intranet/FinanceDept/ExpenseRpt.xls">Expense Report</option>
<option VALUE="frame|http://dk_intranet/FinanceDept/GBMileage.pdf">Green Bay Mileage Chart</option>
</select></form>
</body>
</html>

In the value property for each option tag you specify if it is to open in a frame or a new window. You separate that from the link with a pipes "|" character (or another that you like) and then in the function you split the two values to create a two dimensional array. Then do the checking. I named my frame "main" because a frame name of "body" might cause problems. Hope this helps and good luck.

dmk
06-10-2003, 09:46 PM
Thanks! That worked. If I have to add another entry that should open in a new window, do I just have to add
NewWindow| to the option value instead of
<option Value="frame|...? :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum