在Navigator中调用链接单击事件 [英] invoke link click event in Navigator

查看:90
本文介绍了在Navigator中调用链接单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在IE中这样做


myLink.click(); //调用处理程序就好像用户自己点击了

链接一样。


我需要能够在Netscape Navigator中执行相同操作,


有人可以帮忙吗?

I can do this in IE

myLink.click(); //Invoking the handler as if the user had clicked on the
link themselves.

I need to be able to do the same in Netscape Navigator,

can anyone help ?

推荐答案

news.btinternnet.com写道:
news.btinternnet.com wrote:
我可以在IE中执行此操作

myLink.click(); //调用处理程序,就像用户自己点击了
链接一样。


如果(myLink.href)document.location.href = myLink.href;

我需要能够在Netscape Navigator中执行相同操作,
I can do this in IE

myLink.click(); //Invoking the handler as if the user had clicked on the
link themselves.
if ( myLink.href ) document.location.href = myLink.href;

I need to be able to do the same in Netscape Navigator,




我的导航器安装坏了,我要解决它,但我怀疑

上面的工作正常(它确实在IE和Firefox ......)


-

Rob



My install of Navigator is broken, I''m about to fix it but I suspect
the above will work fine (it does in IE and Firefox...)

--
Rob


RobG写道:
news.btinternnet.com写道:
news.btinternnet.com wrote:
我可以在IE中做到这一点

myLink.click(); //调用处理程序就像用户自己点击了链接一样。
I can do this in IE

myLink.click(); //Invoking the handler as if the user had clicked on
the link themselves.



if(myLink.href)document.location.href = myLink.href;


if ( myLink.href ) document.location.href = myLink.href;


我需要能够在Netscape Navigator中执行相同操作,

I need to be able to do the same in Netscape Navigator,



我的Navigator安装已经坏了,我是即将修复它,但我怀疑上面会工作正常(它在IE和Firefox中...)


My install of Navigator is broken, I''m about to fix it but I suspect
the above will work fine (it does in IE and Firefox...)




修正了我的NN安装,上面修复似乎工作正常。如果你担心该链接可能有一个onclick事件,如果你刮掉href可能不会执行
,那么试试:


if(myLink.href){

if(!myLink.onclick){

document.location.href = myLink.href;

} else {

if(false!= myLink.onclick()){

document.location.href = myLink.href;

}

}

}


这样可以合理地模拟A元素上的点击

(除非还有一些其他事件 - 例如keyup,keydown等 - 你想支持
)。


上面看来看看myLink是否有一个href属性。如果是这样,如果支持onclick内部事件,它会看到

,如果没有,则链接是

跟随。


如果支持onclick,它尝试运行onclick()脚本。如果

它返回除 - false之外的任何内容 - 则遵循链接。如果返回

- false - 则不会跟踪链接(没有任何反应)。


但是,这里存在严重的可访问性问题:没有用户

JavaScript根本无法关注链接。您必须提供

替代方案,以便这些用户可以关注链接。通常的解决方法是使用
提供正常的A元素,然后在页面加载时使用脚本

用JS''增强型'版本替换普通导航。 br $> b $ b -

Rob



Fixed my NN install, the above fix seems to work fine. If you are
concerned that the link may have an onclick event that may not be
executed if you scrape the href, then try:

if ( myLink.href ) {
if ( ! myLink.onclick ) {
document.location.href = myLink.href;
} else {
if ( false != myLink.onclick() ) {
document.location.href = myLink.href;
}
}
}

This provides a reasonable simulation of a click on an A element
(unless there are some other events - e.g. keyup, keydown, etc. - that
you want to support).

The above looks to see if myLink has an href attribute. If so, it sees
if the onclick intrinsic event is supported, if not, the link is
followed.

If onclick is supported, it attempts to run the onclick() script. If
it returns anything other than - false - the link is followed. If
- false - is returned, then the link is not followed (nothing happens).

However, there is a serious accessibility issue here: users without
JavaScript can''t follow the link at all. You must provide an
alternative so that these users can follow links. The usual fix is to
provide normal A elements, then use a script when the page loads to
replace the normal navigation with your JS ''enhanced'' version.
--
Rob


感谢您的帮助,不幸的是,这不是我想要的那样/>
,或许我应该更具体。我正在尝试为MailTo链接调用

邮件助手。使用链接的click事件为

IE和NN执行此操作,但我可以在NN上调用该事件。我需要构建

MailTo:使用Javascript以便我可以自定义外发邮件。


我知道还有其他方法可以使用表单执行此操作和一些CGI

脚本或其他什么,但更喜欢这种方法。我知道你可能会说达到是一个问题,因为不是每个人都有他们的浏览器帮助,无论如何这是我想要实现的目标。


你知道如何用Javascript(

NN)以编程方式调用click事件,我非常想知道答案吗?

最好的问候


-

Terry Burns
http://TrainingOn.net

" RobG" < RG *** @ iinet.net.auau>在消息中写道

新闻:Ft ***************** @ news.optus.net.au ...
Thanks for your help, unfortunately, this was not quite what I was looking
for, perhaps I should have been more specific. I am trying to invoke the
mail helper for the MailTo link. Using the link''s click event does this for
IE and NN, but I can invoke the event on NN. I need to construct the
MailTo: using Javascript so I can customise the outgoing mail message.

I know there are other ways of doing this using a form and a bit of CGI
script or whatever, but prefer this method. I know you may say reach is an
issue because not everyon has helpers on their browser, in any case this is
what I am trying to acheive.

Do you know how to invoke the click event programatically in Javascript (
NN ), I would dearly like to know the answer to that ?

Best Regards

--
Terry Burns
http://TrainingOn.net
"RobG" <rg***@iinet.net.auau> wrote in message
news:Ft*****************@news.optus.net.au...
RobG写道:
news.btinternnet.com写道:
news.btinternnet.com wrote:
我可以在IE中做到这一点

myLink.click(); //调用处理程序就好像用户自己点击了
链接一样。
I can do this in IE

myLink.click(); //Invoking the handler as if the user had clicked on the
link themselves.



if(myLink.href)document.location.href = myLink.href;


if ( myLink.href ) document.location.href = myLink.href;


我需要能够在Netscape Navigator中执行相同操作,

I need to be able to do the same in Netscape Navigator,



我的Navigator安装已经坏了,我是即将解决它,但我怀疑上面会工作正常(它在IE和Firefox中...)


My install of Navigator is broken, I''m about to fix it but I suspect
the above will work fine (it does in IE and Firefox...)



修复我的NN安装,上面的修复似乎工作精细。如果你担心链接可能有onclick事件,如果你刮掉href可能没有执行,那么试试:

if(myLink.href){
if(!myLink.onclick){
document.location.href = myLink.href;
} else {
if(false!= myLink.onclick()){
document.location.href = myLink.href;
}
}

这提供了对A元素点击的合理模拟(除非还有一些其他事件 - 例如keyup,keydown等 - 你想要支持)。

上面看看myLink是否有一个href属性。如果是这样,它会看到
是否支持onclick内部事件,如果没有,则链接是


如果支持onclick,它会尝试运行onclick()脚本。如果
它返回除 - false之外的任何内容 - 则遵循链接。如果返回
- false - 则不会跟踪链接(没有任何反应)。

但是,这里存在一个严重的可访问性问题:没有JavaScript的用户可以'' t完全按照链接。您必须提供
替代方案,以便这些用户可以关注链接。通常的解决方法是提供正常的A元素,然后在页面加载时使用脚本以用JS''增强型'版本替换普通导航。

- -
Rob



Fixed my NN install, the above fix seems to work fine. If you are
concerned that the link may have an onclick event that may not be
executed if you scrape the href, then try:

if ( myLink.href ) {
if ( ! myLink.onclick ) {
document.location.href = myLink.href;
} else {
if ( false != myLink.onclick() ) {
document.location.href = myLink.href;
}
}
}

This provides a reasonable simulation of a click on an A element
(unless there are some other events - e.g. keyup, keydown, etc. - that
you want to support).

The above looks to see if myLink has an href attribute. If so, it sees
if the onclick intrinsic event is supported, if not, the link is
followed.

If onclick is supported, it attempts to run the onclick() script. If
it returns anything other than - false - the link is followed. If
- false - is returned, then the link is not followed (nothing happens).

However, there is a serious accessibility issue here: users without
JavaScript can''t follow the link at all. You must provide an
alternative so that these users can follow links. The usual fix is to
provide normal A elements, then use a script when the page loads to
replace the normal navigation with your JS ''enhanced'' version.
--
Rob



这篇关于在Navigator中调用链接单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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