473,386 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

open new window

Hi,

I have this code in the head of the page:

script language="JavaScript" type="text/JavaScript">
<!--

function goTo(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>

and this bit in the body section:

<form name="form1" method="post" action="">
<select name="select" onChange="goTo('self',this,0)">

Simple put I want the new page to open in a new window, I assumed that
changing the 'self' bit to 'blank' would work but all I get are JavaScript
undefined error messages.

Does anybody have any other ideas as to what I could try ?

Thanks

Jul 23 '05 #1
2 2217
"Andy" <an******@hotmail.com> writes:

script language="JavaScript" type="text/JavaScript">
The language attribute is deprecated and can safely be omitted
<!--
This HTML comment starter can also safely be omitted.

function goTo(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
Yikes. Bad use of eval. You will probably never need to use eval, as
there are better alternatives.

Just use:
function goTo(tObj,selObj,restore) {
tObj.location=selObj.options[selObj.selectedIndex].value;
...
and
<form name="form1" method="post" action="">
<select name="select" onChange="goTo('self',this,0)">
onchange="goTo(self,this,false);"

Simple put I want the new page to open in a new window, I assumed that
changing the 'self' bit to 'blank' would work but all I get are JavaScript
undefined error messages.
This code is only built to open in existing windows.
Does anybody have any other ideas as to what I could try ?


function goToNew(winName,selObj,restore) {
var win = window.open(selObj.options[selObj.selectedIndex],winName);
if (restore) {selObj.selectedIndex=0;}
return win;
}

called as, e.g.:
onchange="goToNew('_blank',this,false);"

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2
On Sat, 17 Apr 2004 20:42:42 +0100, Andy <an******@hotmail.com> wrote:
I have this code in the head of the page:

script language="JavaScript" type="text/JavaScript">
The language attribute is deprecated, and the presence of the type
attribute makes it redundant. Remove it.
<!--
Script hiding is a practice that is now obsolete. Remove the SGML comment
delimiters.
function goTo(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
Why are you using eval()? I don't see why you can't just make targ an
object reference and then write:

targ.location.href = selObj.options[ selObj.selectedIndex ].value;

Notice that there is no need to convert the value property to a string.
The form control values are *always* returned as strings.
if (restore) selObj.selectedIndex=0;
}
//-->
Remove this delimiter along with the first.
</script>

and this bit in the body section:

<form name="form1" method="post" action="">
<select name="select" onChange="goTo('self',this,0)">
To work with the changes above, change the call to

goTo(self,this,false)

I changed the last argument to false because it makes more sense to pass
booleans when evaluating booleans.
Simple put I want the new page to open in a new window, I assumed that
changing the 'self' bit to 'blank' would work but all I get are
JavaScript undefined error messages.
That's because "self" is an object reference to the current window
(equivalent to window.self or window), whereas "blank" isn't defined at
all.
Does anybody have any other ideas as to what I could try ?


A call to window.open(), perhaps?

Two things to note:

1) Don't perform navigation actions on the "change" event.
2) Avoid new windows completely, if possible.

If I use my mouse wheel to change the value, the event will fire every
time even though I probably haven't chosen a destination yet. Similarly,
if I make a mistake when choosing a value, I will not get an opportunity
(unless I'm very quick) to correct it. Use a button instead.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Paul | last post by:
I link to a web site from an Excel spreadsheet. The page i link to is getCookie.asp which sets a cookie then returns back some html which opens a new window, to the same site but a different page...
6
by: Les | last post by:
Hi, I'd like to find out how to use the window.open() script in Fireworks MX. I have posted my question in the Fireworks forum but didn't get any replies. Since it's javascript, maybe someone...
10
by: Marshall Dudley | last post by:
When I do the following line in Netscape, the popup loads as it should, but the parent window usually, but not always, reloads as well. <a href="#"...
10
by: David McCulloch | last post by:
The following code opens a new window, but the "resizeTo" doesn't resize it. Why not? (Don't ask why I simply did not open the window with the new size....my original problem was how to open a...
2
by: Samir Pandey | last post by:
Hello, I am using the following javascript code to open a new window. Somehow, IE always opens a new window. It doesn't open target url in the window name given. All i want is, if there is a...
3
by: NeverLift | last post by:
But, if it's not open, I don't want to open it . . . using window.open will open it if it doesn't exist, even if the url in that open is null (the window is then empty -- but it's open). The...
2
by: Larry R Harrison Jr | last post by:
I have pull-down menus in javascript and I have the code for opening a link in a new window. But I want it to open a full-sized window. I can't figure out the syntax. What I have so far: ...
8
by: Dominic Tocci | last post by:
I'm searching for a way to use window.open on my web page to open a window in firefox that allows the sidebars to work (bookmarks, history, etc). When I use the following: var...
7
by: anthony.turcotte | last post by:
Hi, I've looked for a solution to this problem on google, read posts in this newsgroup and I still haven't found anything that could help me. Here's the scenario. 1. User accesses...
13
by: Geoff Fox | last post by:
I am in the final moments of designing a new website. One of the pages (http://www.auditionfactory.com/samples.php) has four links to show sample work. I would like these links to open new...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.