Gossamer Forum
Home : General : Internet Technologies :

Javascript new window

Quote Reply
Javascript new window
Hi

I've got the following code:

Code:
<select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
<option value="link.html">link</option>
</select>

How can I make it so that when the user selects an option the new URL appaears in a new window instead of the same, parent window?

Thanks!

- wil
Quote Reply
Re: [Wil] Javascript new window In reply to
Simple suggestion...use target="newwin" in the form action line...

Example:

<form action="someaction" method="post" target="newwin">

========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Heckler] Javascript new window In reply to
Nope, didn't work. Thanks anyway.

- wil
Quote Reply
Re: [Wil] Javascript new window In reply to
Aha. I didn't notice that Dreamweaver had put the following function in too:

Code:
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}

Can anything be ammended in that?

- wil
Quote Reply
Re: [Wil] Javascript new window In reply to
If you take out the javascript and simply use the target attribute in the form action line, then it will open a new window.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Heckler] Javascript new window In reply to
Hmm, that doesn't seem to do it. It's still looking to call a JS function which is no longer there.

I'll look around for a simpler solution I think.

Cheers

- wil
Quote Reply
Re: [Wil] Javascript new window In reply to
How about posting the complete form codes???

The simple example that WILL work is:

Quote:

<form action="someaction" method="somemethod" target="newwin">
<select name="URL" size="1">
<option value="link.html">Some Link Title</option>
</select>
<input type="submit" name="go" value="Go!">
</form>

========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Heckler] Javascript new window In reply to
Hi Eliot

That would work well for a script, as it requests "someaction?" and then the value chosen. But it won't work for a simple redirect to another page (without using a script).

Thanks

- wil
Quote Reply
Re: [Wil] Javascript new window In reply to
....will still work without a form action.
Quote Reply
Re: [RedRum] Javascript new window In reply to
Hm. That's funny. Here's my *exact* code from Eliot's post.

Code:
<form action="someaction" method="somemethod" target="newwin">
<select name="URL" size="1">
<option selected>-- please select sample page --</option>
<option>-</option>
<option value="/2002/pdf/446.pdf">446. Bridgend County
Council</option>
<option value="/2002/pdf/447.pdf">447. Bridgend County
Council (cont.)</option>
</select>
<input type="submit" name="go" value="Go!">
</form>


When I select an option and hit "go!" the browser does open a new window, but takes me to:

Code:
/2002/html/someaction?URL=%2F2002%2Fpdf%2F446.pdf&go=Go%21

Which is not exactly the page I want ;-)

The problem from where I see is that it's trying to call the script "somecation" and pass the options to it - which is standard behaviour for forms on the web.

- wil
Quote Reply
Re: [RedRum] Javascript new window In reply to
Now without any FORM tag it assumed that the current page is the script I'm passing information to and I reach:

Code:
/2002/html/c_10.html?URL=%2F2002%2Fpdf%2F446.pdf&go=Go%21

Which is standards behaviour. The browser is doing it's job properly. That's how it's suppose to handle forms.

So I guess the only was is Javascript?

- wil
Quote Reply
Re: [Wil] Javascript new window In reply to
Wil,

YOU need to REPLACE someaction and somemethod with the EXACT form action and the method you are using!

I thought you would've figured that out...I was simply giving an example.

If you are looking for a "redirection" script, there are many good Perl scripts to do this out there in the web...and using the target attribute will work.
========================================
Buh Bye!

Cheers,
Me
Quote Reply
Re: [Heckler] Javascript new window In reply to
Hi Eliot

That's precisely my point - I *don't* want to be using any kind of server-side script.

That's why I was asking someone if they could modify my JS function, and hence, the thread subject.

Cheers

- wil
Quote Reply
Re: [Wil] Javascript new window In reply to
Okay...fine...

Look at the following web site:

http://www.anthro-globe.com

Feel free to download the drop-down menu codes via the source code...

And you can download and use the following js file:

http://anthro-globe.com/plugins/js/dropdown.js

(Best method of downloading the file is via IE)

The form in that site that I wrote will allow you to use target as an attribute in the form action line. And it works in both Netscape 4.6 and 4.73 as well as IE 4.0 and above.

Good luck and goodbye.




========================================
Buh Bye!

Cheers,
Me

Last edited by:

Heckler: Jan 9, 2002, 9:05 AM
Post deleted by RedRum In reply to

Last edited by:

RedRum: Jan 9, 2002, 9:08 AM
Quote Reply
Re: [Heckler] Javascript new window In reply to
Thank you, Eliot.

Very kind of you.

- wil
Quote Reply
Re: [Wil] Javascript new window In reply to
Hi Wil,

Just change your script like:

function MM_jumpMenu(selObj,restore){ //v3.0
var url = selObj.options[selObj.selectedIndex].value;
if (url) window.open(url);
if (restore) selObj.selectedIndex=0;
}

And HTML script should be:
<select name="menu1" onChange="MM_jumpMenu(this,0)">
<option></option>
<option value="link.html">link</option>
</select>

Cheers,

TheStone.


B.

Last edited by:

TheStone: Jan 9, 2002, 9:49 AM
Quote Reply
Re: [TheStone] Javascript new window In reply to
Thanks, "TheStone"! I was kinda hoping you would pop in and share your wizdom :-)

Cheers

- wil
Quote Reply
Re: [TheStone] Javascript new window In reply to
What about if you want the links to open to the same window each time?

For example, I like all of my links from my page to go to a window that I call "view_frame...
Quote Reply
Re: [groversd] Javascript new window In reply to
Add the script below into your html file:

<script>
function rs(n, u, w, h, l, t, s) {
args="width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ",resizable=no,scrollbars=" + s + ",status=0";
remote=window.open(u, n, args);
if (remote != null) {
if (remote.opener == null)
remote.opener = self;
}
}
</script>

So, you can use it as:

- Link: <a href="javascript:rs('win_name', 'URL', win_width, win_height, win_top, win_left, win_scrollbars)">Open window</a>

- Or <input type="button" name="blink" value="Open window" onclick="rs('win_name', 'URL', win_width, win_height, win_top, win_left, win_scrollbars)">

Hope that helps.

TheStone.

B.
Quote Reply
Re: [TheStone] Javascript new window In reply to
I'm sorry. I was able to decipher most of it, but I was not able to ascertain whether this can be used with a drop-down menu.