By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,027 Members | 803 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,027 IT Pros & Developers. It's quick & easy.

Open new window with JS

P: n/a
I want to include a button that has rollover effects and also is a link to a
page that will open in a new window. Here's the code I am using:

<A
HREF="javascript:window.open('email_me.htm','','sc rollbars=0,menubar=0,heigh
t=260,width=400,toolbar=0');"
ONMOUSEOVER="changeImagesX('EmailMe_Layer_1',
'images/EmailMe_Layer-1-over.gif'); return true;"
ONMOUSEOUT="changeImagesX('EmailMe_Layer_1', 'images/EmailMe_Layer-1.gif');
return true;">
<IMG NAME="EmailMe_Layer_1" SRC="images/EmailMe_Layer-1.gif" BORDER=0
width="140" height="25"></A>

Everything works OK - the rollovers work and when the button is clicked the
new window opens. The problem is that the original window goes blank and
displays only the text [object]. How can I do what I want and have the
original window retain its contents?

You can see this at http://www.pgacon.com/testpage.htm

--
Peter Aitken

Remove the crap from my email address before using.
Jul 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Lee
Peter Aitken said:

I want to include a button that has rollover effects and also is a link to a
page that will open in a new window. Here's the code I am using:

<A
HREF="javascript:window.open('email_me.htm','','s crollbars=0,menubar=0,heigh
t=260,width=400,toolbar=0');"
ONMOUSEOVER="changeImagesX('EmailMe_Layer_1',
'images/EmailMe_Layer-1-over.gif'); return true;"
ONMOUSEOUT="changeImagesX('EmailMe_Layer_1', 'images/EmailMe_Layer-1.gif');
return true;">
<IMG NAME="EmailMe_Layer_1" SRC="images/EmailMe_Layer-1.gif" BORDER=0
width="140" height="25"></A>

Everything works OK - the rollovers work and when the button is clicked the
new window opens. The problem is that the original window goes blank and
displays only the text [object]. How can I do what I want and have the
original window retain its contents?


The HREF attribute tells the link what to display in the current
window. You're telling it to display the value returned by the
javascript method "window.open(...)". That value is a window
object, which displays as "[object]".

If you don't want to display the value of a Javascript expression,
don't use the "javascript:" protocol. If you don't want to change
the contents of the current window at all, have the onclick handler
of the link return false.

This also makes it possible for people to use the link if they
don't have Javascript enabled.

<a href="email_me.htm"
onclick="window.open('email_me.htm','validName','h eight=260,width=400);return
false"
onmouseover="changeImagesX('EmailMe_Layer_1','imag es/EmailMe_Layer-1-over.gif');
return true;"
onmouseout="changeImagesX('EmailMe_Layer_1','image s/EmailMe_Layer-1.gif');
return true;"><img
name="EmailMe_Layer_1"
src="images/EmailMe_Layer-1.gif"
border="0"
width="140"
height="25"></A>

Jul 23 '05 #2

P: n/a
"Lee" <RE**************@cox.net> wrote in message
news:cb*********@drn.newsguy.com...
Peter Aitken said:

I want to include a button that has rollover effects and also is a link to apage that will open in a new window. Here's the code I am using:

<A
HREF="javascript:window.open('email_me.htm','','s crollbars=0,menubar=0,heig

h
t=260,width=400,toolbar=0');"
ONMOUSEOVER="changeImagesX('EmailMe_Layer_1',
'images/EmailMe_Layer-1-over.gif'); return true;"
ONMOUSEOUT="changeImagesX('EmailMe_Layer_1', 'images/EmailMe_Layer-1.gif');return true;">
<IMG NAME="EmailMe_Layer_1" SRC="images/EmailMe_Layer-1.gif" BORDER=0
width="140" height="25"></A>

Everything works OK - the rollovers work and when the button is clicked thenew window opens. The problem is that the original window goes blank and
displays only the text [object]. How can I do what I want and have the
original window retain its contents?


The HREF attribute tells the link what to display in the current
window. You're telling it to display the value returned by the
javascript method "window.open(...)". That value is a window
object, which displays as "[object]".

If you don't want to display the value of a Javascript expression,
don't use the "javascript:" protocol. If you don't want to change
the contents of the current window at all, have the onclick handler
of the link return false.

This also makes it possible for people to use the link if they
don't have Javascript enabled.

<a href="email_me.htm"

onclick="window.open('email_me.htm','validName','h eight=260,width=400);retur
n false"
onmouseover="changeImagesX('EmailMe_Layer_1','imag es/EmailMe_Layer-1-over.gi
f'); return true;"
onmouseout="changeImagesX('EmailMe_Layer_1','image s/EmailMe_Layer-1.gif'); return true;"><img
name="EmailMe_Layer_1"
src="images/EmailMe_Layer-1.gif"
border="0"
width="140"
height="25"></A>


Thanks for the info, Lee - it helped but it is still not right - the new
page opens in the original browser window instead of a new window. Here's
the code:

<a href="email_me.htm"
onclick="window.open('email_me.htm','validName','h eight=260,width=400);retur
n false;"
onmouseover="changeImagesX('EmailMe_Layer_1','imag es/EmailMe_Layer-1-over.gi
f');return true;"
onmouseout="changeImagesX('EmailMe_Layer_1','image s/EmailMe_Layer-1.gif');re
turn true;">
<img name="EmailMe_Layer_1"
src="images/EmailMe_Layer-1.gif"
border="0"
width="140"
height="25"></A>

The test page is still at www.pgacon.com/testpage.htm

Any other ideas? Thanks-

--
Peter Aitken

Remove the crap from my email address before using.
Jul 23 '05 #3

P: n/a
Peter Aitken wrote:
Lee wrote: <snip> <a href="email_me.htm"
onclick="window.open('email_me.htm','validName','h eight=260,width=400);
^ ^
Error: unterminated string constant.
return false;" <snip> Any other ideas?


Read (and understand) the error messages that the browser generates.

Richard.
Jul 23 '05 #4

P: n/a
Lee
Peter Aitken said:
Thanks for the info, Lee - it helped but it is still not right - the new
page opens in the original browser window instead of a new window. Here's
the code:

<a href="email_me.htm"
onclick="window.open('email_me.htm','validName',' height=260,width=400);retur
n false;"
onmouseover="changeImagesX('EmailMe_Layer_1','ima ges/EmailMe_Layer-1-over.gi
f');return true;"
onmouseout="changeImagesX('EmailMe_Layer_1','imag es/EmailMe_Layer-1.gif');re
turn true;">
<img name="EmailMe_Layer_1"
src="images/EmailMe_Layer-1.gif"
border="0"
width="140"
height="25"></A>


I made a typo that causes the window.open() call to fail, which
causes the "return false" to never be executed, allowing the
link to be followed, opening the page in the current window.

There should be a closing single-quote after the window attributes:

window.open('email_me.htm','validName','height=260 ,width=400');returen false

Jul 23 '05 #5

P: n/a
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message
news:cb*******************@news.demon.co.uk...
Peter Aitken wrote:
Lee wrote:

<snip>
<a href="email_me.htm"

onclick="window.open('email_me.htm','validName','h eight=260,width=400);
^ ^
Error: unterminated string constant.
return false;"

<snip>
Any other ideas?


Read (and understand) the error messages that the browser generates.

Richard.


Ah, but it did not generate any error messages! In any event the problem is
fixed now.
--
Peter Aitken

Remove the crap from my email address before using.
Jul 23 '05 #6

P: n/a
"Lee" <RE**************@cox.net> wrote in message
news:cb********@drn.newsguy.com...
Peter Aitken said:
Thanks for the info, Lee - it helped but it is still not right - the new
page opens in the original browser window instead of a new window. Here's
the code:

<a href="email_me.htm"
onclick="window.open('email_me.htm','validName',' height=260,width=400);retu

r
n false;"


onmouseover="changeImagesX('EmailMe_Layer_1','ima ges/EmailMe_Layer-1-over.g

i
f');return true;"


onmouseout="changeImagesX('EmailMe_Layer_1','imag es/EmailMe_Layer-1.gif');r

e
turn true;">
<img name="EmailMe_Layer_1"
src="images/EmailMe_Layer-1.gif"
border="0"
width="140"
height="25"></A>


I made a typo that causes the window.open() call to fail, which
causes the "return false" to never be executed, allowing the
link to be followed, opening the page in the current window.

There should be a closing single-quote after the window attributes:

window.open('email_me.htm','validName','height=260 ,width=400');returen

false


Yikes, I should have caught that myself! Thanks a lot - it's been a big
help.
--
Peter Aitken

Remove the crap from my email address before using.
Jul 23 '05 #7

P: n/a
Peter Aitken wrote:


Ah, but it did not generate any error messages! In any event the problem is
fixed now.


Yes it did.
Mick
Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.