469,306 Members | 1,901 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

n00b ? href=javascript

Can anybody explain why when I have a hyperlink on a page with the code
similar to below, after the user clicks on the link, the desired window
opens but the page with the hyperlink changes to a new page with simply the
value "[object]" on it? I want the original page to remain unchanged....
thanks for the insight to a javascript n00bie... :)

<a href="javascript:window.open('wireless.htm', 'pjtdetails',
config='height=400, width=400, toolbar=no, menubar=no, scrollbars=yes,
resizable=yes, location=no')">
asdfalkjsdflbkajsdf</a>
Jul 20 '05 #1
11 1794

try this instead: (all on one line)

<a href="#" onClick="window.open('wireless.htm',
'pjtdetails','height=400, width=400, toolbar=no, menubar=no,
scrollbars=yes,resizable=yes, location=no')">click me</a>
HTH

Al.

On Wed, 14 Jan 2004 16:15:49 -0500, "Dana Smith"
<da********@comcast.net> wrote:
<a href="javascript:window.open('wireless.htm', 'pjtdetails',
config='height=400, width=400, toolbar=no, menubar=no, scrollbars=yes,
resizable=yes, location=no')">


Jul 20 '05 #2
On Wed, 14 Jan 2004 16:15:49 -0500, Dana Smith <da********@comcast.net>
wrote:
Can anybody explain why when I have a hyperlink on a page with the code
similar to below, after the user clicks on the link, the desired window
opens but the page with the hyperlink changes to a new page with simply
the
value "[object]" on it? I want the original page to remain unchanged....
thanks for the insight to a javascript n00bie... :)
This is one of the hazards of using javascript: URIs. The better method is
using the onclick event handler:

<A href="" onclick="window.open(...);return false">text</A>

Notice the statement, 'return false'? This is also required to stop the
browser from following the link (href="" is the same as the current page).
Unless there is a specific reason to use a link, you should use a button
instead:

<BUTTON type="button" onclick="window.open(...)">text</BUTTON>

Notice that the return statement is not needed.

The moral of this story is, NEVER use javascript: URIs.
<a href="javascript:window.open('wireless.htm', 'pjtdetails',
config='height=400, width=400, toolbar=no, menubar=no, scrollbars=yes,
resizable=yes, location=no')">
asdfalkjsdflbkajsdf</a>


The 'features' string (height=400,...) shouldn't contain any spaces. That
is, it should be written:

"height=400,width=400,scrollbars,resizable"

Also notice that I omitted the disabled features. Boolean (yes/no) options
default to 'no' when left out.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #3
On Wed, 14 Jan 2004 21:59:55 +0000, Harag
<ha***@REMOVETHESECAPITALSsofthome.net> wrote:

[Quoted material snipped]
try this instead: (all on one line)

<a href="#" onClick="window.open('wireless.htm',
'pjtdetails','height=400, width=400, toolbar=no, menubar=no,
scrollbars=yes,resizable=yes, location=no')">click me</a>


This still has a problem; you don't cancel the event. Once the new window
is opened, the original page will still be changed. Granted, it goes back
to the same page, but it shouldn't happen at all, in this case.
Furthermore, there shouldn't be any spaces in the 'features' string. You
should append the following to the handler code (including the semi-colon):

;return false

Mike

And please, don't top-post. Place your response below, or amongst, quoted
material and make sure you trim it as necessary. See my response to the
OP, and posts to long threads (by regular posters) for examples.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #4
Michael Winter wrote on 14 jan 2004 in comp.lang.javascript:
<BUTTON type="button" onclick="window.open(...)">text</BUTTON>


A button is default of type button

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #5
DU
Evertjan. wrote:
Michael Winter wrote on 14 jan 2004 in comp.lang.javascript:

<BUTTON type="button" onclick="window.open(...)">text</BUTTON>

A button is default of type button


Quite on the contrary. A button is default of type submit.

http://www.w3.org/TR/html401/interac...ml#edef-BUTTON

http://www.htmlhelp.org/reference/ht...ms/button.html

DU
Jul 20 '05 #6
On 14 Jan 2004 22:37:20 GMT, Evertjan. <ex**************@interxnl.net>
wrote:
Michael Winter wrote on 14 jan 2004 in comp.lang.javascript:
<BUTTON type="button" onclick="window.open(...)">text</BUTTON>


A button is default of type button


Debatable.

As far as Microsoft are concerned, the default is indeed a push button.
According to the HTML 4.01 specification, the default is a submit button.

I prefer to abide by the specification.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #7
DU
Michael Winter wrote:
On Wed, 14 Jan 2004 16:15:49 -0500, Dana Smith <da********@comcast.net>
wrote:
Can anybody explain why when I have a hyperlink on a page with the code
similar to below, after the user clicks on the link, the desired window
opens but the page with the hyperlink changes to a new page with
simply the
value "[object]" on it? I want the original page to remain unchanged....
thanks for the insight to a javascript n00bie... :)

This is one of the hazards of using javascript: URIs. The better method
is using the onclick event handler:

<A href="" onclick="window.open(...);return false">text</A>

Notice the statement, 'return false'? This is also required to stop the
browser from following the link (href="" is the same as the current
page). Unless there is a specific reason to use a link, you should use a
button instead:

<BUTTON type="button" onclick="window.open(...)">text</BUTTON>

Notice that the return statement is not needed.

The moral of this story is, NEVER use javascript: URIs.
<a href="javascript:window.open('wireless.htm', 'pjtdetails',
config='height=400, width=400, toolbar=no, menubar=no, scrollbars=yes,
resizable=yes, location=no')">
asdfalkjsdflbkajsdf</a>

The 'features' string (height=400,...) shouldn't contain any spaces.
That is, it should be written:

"height=400,width=400,scrollbars,resizable"

Also notice that I omitted the disabled features. Boolean (yes/no)
options default to 'no' when left out.

Mike


Your post is good and what you said is correct. But it still isn't a
complete answer.

1- If javascript support is disabled, the wireless.htm resource will not
be loaded at all.
E.g.
<a href="wireless.htm" target="pjtdetails"
onclick="window.open(this.href, this.target,
'height=400,width=400,scrollbars,resizable'); return
false;">asdfalkjsdflbkajsdf</a>
would avoid that.

2- There are no accessibility support for the link to indicate that the
link will normally open a new separate window. Adding a title attribute
along with a new-window icon image would solve that. Doing so gives
users more freedom (use right-click, choose contextmenu, modify
settings,etc)
E.g.
<a href="wireless.htm" target="pjtdetails"
onclick="window.open(this.href, this.target,
'height=400,width=400,scrollbars,resizable'); return false;"
title="Clicking the link will create a new window
(popup)">asdfalkjsdflbkajsdf</a>
would avoid that.

3- If the popup goes behind and if the user clicks again the link
hoping/expecting the popup to be brought back up on top of the opener,
nothing will happen. This happens often and this is known to be a very
frequent usability problem for users. Here, you need to store a
reference to the window object in a global variable and verify if the
window was not closed.

I have working examples on all this:

This following page sums up all of the above into a single script
function OpenRequestedPopup
http://www10.brinkster.com/doctorunc...pera7Bugs.html

Popup windows and Netscape 7: interactive demos
(the demos will work in MSIE 6, Opera 7.x, etc.)
http://www10.brinkster.com/doctorunc...Netscape7.html

DU
Jul 20 '05 #8
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
<snip>
<BUTTON type="button" onclick="window.open(...)">text</BUTTON>
A button is default of type button


Debatable.

As far as Microsoft are concerned, the default is indeed a push
button. According to the HTML 4.01 specification, the default is
a submit button.

I prefer to abide by the specification.


The effect of the discrepancy is that always including the type
attribute in button elements is a better idea than relying on the
defaults (because they will commonly not be uniform).

Richard.
Jul 20 '05 #9
On Wed, 14 Jan 2004 18:04:21 -0500, DU <dr*******@hotREMOVETHISmail.com>
wrote:
Michael Winter wrote:

This is one of the hazards of using javascript: URIs. The better method
is using the onclick event handler:

<A href="" onclick="window.open(...);return false">text</A>

<snipped the remainder of my original post>
Your post is good and what you said is correct. But it still isn't a
complete answer.

1- If javascript support is disabled, the wireless.htm resource will not
be loaded at all.
I realise this.
2- There are no accessibility support for the link to indicate that the
link will normally open a new separate window. Adding a title attribute
along with a new-window icon image would solve that. Doing so gives
users more freedom (use right-click, choose contextmenu, modify
settings,etc)
Understand that, but didn't think about it at the time.
3- If the popup goes behind and if the user clicks again the link
hoping/expecting the popup to be brought back up on top of the opener,
nothing will happen. This happens often and this is known to be a very
frequent usability problem for users. Here, you need to store a
reference to the window object in a global variable and verify if the
window was not closed.


Hadn't thought of that at all - I wouldn't expect the user to do it.

The problem I find is one of information overload. In some cases
(particularly with novices), some of things I might think of will do
nothing but confuse the OP so I tend to be selective. However, I'll admit
that most of the time, some suggestions (like the latter two you raised)
simply don't occur to me.

Thank you.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #10
Lee
Michael Winter said:
The moral of this story is, NEVER use javascript: URIs.


Never use them in links, particularly simply for their side effects.
There are some cases where they are useful for their original purpose,
which is to replace the current page contents with the result of the
evaluated Javascript expression.

Of course, you have to know that the visitor has Javascript enabled.

Jul 20 '05 #11
On Wed, 14 Jan 2004 22:30:28 GMT, Michael Winter
<M.******@blueyonder.co.invalid> wrote:

[Quoted material snipped]
This still has a problem; you don't cancel the event. Once the new window
is opened, the original page will still be changed. Granted, it goes back
to the same page, but it shouldn't happen at all, in this case.
Furthermore, there shouldn't be any spaces in the 'features' string. You
should append the following to the handler code (including the semi-colon):

;return false
Ahh yes forgot about the return false; bit on the end. thanks for
pointing that out :)

The point about spaces in the "features" string is new to me so thanks
for that...
And please, don't top-post. Place your response below, or amongst, quoted
material and make sure you trim it as necessary. See my response to the
OP, and posts to long threads (by regular posters) for examples.


I just had this same sort of message in the MS JScript group. I'm new
to Jscript and just started subscribing to these two groups. FYI heres
what I put in the other group:

"Sorry about that. Some groups dont mind it and others do...I'm fairly
new to this group so I'll keep that in mind. Personally I dont mind it
as I use "Free agent" to read newsgroups and it saves me scrolling
when people have put quick replies at the top... as I can see the
previous reply just by clicking on the tree as its an offline reader."

From now on I'll convert over to not top posting. Then I'm safe where
ever I post.

Al.

Jul 20 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Steve - DND | last post: by
1 post views Thread by Julius Mong | last post: by
53 posts views Thread by usenet | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.