n00b? HREF = JavaScript的 [英] n00b ? href=javascript

查看:66
本文介绍了n00b? HREF = JavaScript的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以解释为什么当我在页面上有超链接时,代码

类似于下面,在用户点击链接后,所需的窗口

打开但是带有超链接的页面更改为一个新页面,其中只有

值" [object]"在上面?我希望原始页面保持不变....

感谢您对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>

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>

推荐答案



试试这个:(全部在一行)


< a HREF ="#" onClick =" window.open(''wireless.htm'',

''pjtdetails'',''height = 400,width = 400,toolbar = no,menubar = no,

scrollbars = yes,resizable = yes,location = no'')">点击我< / a>

HTH


Al。


2004年1月14日星期三16:15:49 -0500,Dana Smith

< da ***** ***@comcast.net>写道:

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'')">
<a href="javascript:window.open(''wireless.htm'', ''pjtdetails'',
config=''height=400, width=400, toolbar=no, menubar=no, scrollbars=yes,
resizable=yes, location=no'')">






2004年1月14日星期三16:15:49 -0500,Dana Smith< da ******** @ comcast.net>

写道:
On Wed, 14 Jan 2004 16:15:49 -0500, Dana Smith <da********@comcast.net>
wrote:
任何人都可以解释为什么当我在页面上有超链接时,代码类似于以下,用户点击后链接,所需的窗口打开,但带有超链接的页面更改为新页面,只需
值[object]在上面?我希望原始页面保持不变....
感谢javascript n00bie的洞察力... :)


这是使用javascript的危险之一 :URI。使用onclick事件处理程序的方法更好:


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


注意语句''return false''?这也需要停止

浏览器跟随链接(href =""与当前页面相同)。

除非有特殊原因要使用链接,你应该使用一个按钮

代替:


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


请注意,不需要return语句。


这个故事的寓意是,永远不要使用javascript :URI。

< a href =" javascript :window。 open(''wireless.htm'',''pjtdetails'',
config =''height = 400,width = 400,toolbar = no,menubar = no,scrollbars = yes,
resizable =是的,location = no'')">
asdfalkjsdflbkajsdf< / a>
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>




''features''字符串(height = 400,。 ..)不应该包含任何空格。那个

,应写成:


" height = 400,width = 400,滚动条,可调整大小


另请注意,我省略了禁用的功能。布尔(是/否)选项

默认为'no'时遗漏。


Mike


-

Michael Winter
M.******@blueyonder .co.inva lid(将.invalid替换为.uk以回复)



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)


2004年1月14日星期三21:59: 55 +0000,Harag

< ha *** @ REMOVETHESECAPITALSsofthome.net>写道:


[引用材料剪辑]
On Wed, 14 Jan 2004 21:59:55 +0000, Harag
<ha***@REMOVETHESECAPITALSsofthome.net> wrote:

[Quoted material snipped]
试试这个:(全部在一行)

< ; a href ="#" onClick =" window.open(''wireless.htm'',
''pjtdetails'',''height = 400,width = 400,toolbar = no,menubar = no,
scrollbars =是的,resizable = yes,location = no'')">点击我< / a>
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>




这仍有问题;你不能取消这个活动。打开新窗口

后,原始页面仍会被更改。当然,它返回到同一页面的
,但在这种情况下它根本不会发生。

此外,不应该有任何空格在''features''字符串中。你将
附加到处理程序代码中(包括分号):


;返回false


迈克


请不要过头。将您的回复放在下面,或引用

材料中,并确保根据需要修剪它。请参阅我对

OP的回复,并发布到长线程(通过常规海报)的示例。


-

Michael Winter
M.******@blueyonder.co.inva 盖子(更换" .invalid" with.ukto to reply)



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)


这篇关于n00b? HREF = JavaScript的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆