处理具有onclick问题的锚点的href [英] handling of # in href of an anchor that has an onclick question

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

问题描述

如果FF使用包含#和hclick事件的href来处理

锚点之间似乎存在严重差异。


如果onclick事件返回false,IE不会改变

window.location.href包含#。 FF确实如此。


(例如)< a href =" #moo"的onclick = QUOT;警报(も);返回false;">

点击IE后,浏览器中的位置栏显示

" www.moo.cow / index.htm"。

点击FF后,浏览器中的位置栏显示

" www.moo.cow / index.htm#moo"。


可以有人告诉我为什么会这样吗?它给我带来了一些其他的好东西......


泰勒

There seems to be a serious difference between how FF an IE handle an
anchor with an href containing a # and an onclick event.

If the onclick event returns false, IE does not change
window.location.href to include the #. FF does.

(eg) <a href="#moo" onclick="alert(''moo''); return false;">
After clicking in IE, location bar in browser shows
"www.moo.cow/index.htm".
After clicking in FF, location bar in browser shows
"www.moo.cow/index.htm#moo".

Can anyone tell me why this should be so? It screws up some otherwise
nifty things for me...

Tyler

推荐答案

Logos写道:
(例如)< a href =" #moo"的onclick = QUOT;警报(も);返回false;">
点击IE后,浏览器中的位置栏显示
www.moo.cow / index.htm。
点击FF后,位置栏进入浏览器显示
www.moo.cow / index.htm #moo。
(eg) <a href="#moo" onclick="alert(''moo''); return false;">
After clicking in IE, location bar in browser shows
"www.moo.cow/index.htm".
After clicking in FF, location bar in browser shows
"www.moo.cow/index.htm#moo".




首次点击链接时,从文档中获取值。位置。

然后,将其存储在一个变量中,并调用setTimeout,并使用另一个

函数将该位置复制回document.location。


我唯一不知道的是,这是否会导致页面重新加载

,但是,我认为这可能有用。


Logos写道:
在IE如何处理
锚点与包含#的href之间似乎有一个严重的区别onclick事件。


这是一个不正确的假设。

如果onclick事件返回false,IE不会改变
window.location.href来包含# 。 FF呢。


这是一个错误的结论。

(例如)< a href =" #moo"的onclick = QUOT;警报(も);返回false;">
点击IE后,浏览器中的位置栏显示
www.moo.cow / index.htm。
点击FF后,位置栏进入浏览器显示
www.moo.cow / index.htm #moo。
谁能告诉我为什么会这样?
There seems to be a serious difference between how FF an IE handle an
anchor with an href containing a # and an onclick event.
That is an incorrect assumption.
If the onclick event returns false, IE does not change
window.location.href to include the #. FF does.
That is an incorrect conclusion.
(eg) <a href="#moo" onclick="alert(''moo''); return false;">
After clicking in IE, location bar in browser shows
"www.moo.cow/index.htm".
After clicking in FF, location bar in browser shows
"www.moo.cow/index.htm#moo".
Can anyone tell me why this should be so?




因为你的例子与你正在做的事情不完全匹配。

如果你将上面的内容放在一个实际的文件中并进行测试,那么它将起作用

例如,


< a href =" #moo的onclick = QUOT;警报(も); return false;"> temp< / a>

< br>< br>

< span onclick =" alert(window.location.href )">点击提醒位置< / span>


点击链接然后跨度提醒正确的网址(没有#moo)和

位置栏也没有显示#moo。


我怀疑你的实际测试用例调用了一个函数,而那个函数

导致firefox出错,然后导致返回false永远不会被调用
,这会使#moo href被跟踪。


总是发布实际说明问题的示例代码。
http://www.javascripttoolbox.com/clj/#getanswers


-

Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com



Because your example doesn''t match exactly with what you are doing.
If you put the above in an actual file and did the test, it would work as
expected.

For example,

<a href="#moo" onclick="alert(''moo''); return false;">temp</a>
<br><br>
<span onclick="alert(window.location.href)">Click to alert location</span>

Clicking the link then the span alerts the correct url (without #moo) and
the location bar doesn''t show #moo either.

I suspect that your actual test case calls a function, and that function
causes an error in firefox, which then causes the return false to never be
called, which makes the #moo href be followed.

Always post example code that actually illustrates the problem.
http://www.javascripttoolbox.com/clj/#getanswers

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


Logos写道:
那里似乎是FF如何处理一个
锚点与一个包含#和一个onclick事件的href之间的严重区别。


没有区别

如果onclick事件返回false,IE不会改变
window.location.href来包含# 。 FF呢。


不,这不会发生。

(例如)< a href =" #moo"的onclick = QUOT;警报(も);返回false;">
点击IE后,浏览器中的位置栏显示
www.moo.cow / index.htm。


正确

点击FF后,浏览器中的位置栏显示
www.moo.cow / index.htm #moo。


不正确。我刚试过它。

谁能告诉我为什么会这样呢?
There seems to be a serious difference between how FF an IE handle an
anchor with an href containing a # and an onclick event.
There isn''t a difference
If the onclick event returns false, IE does not change
window.location.href to include the #. FF does.
No, this does not happen.
(eg) <a href="#moo" onclick="alert(''moo''); return false;">
After clicking in IE, location bar in browser shows
"www.moo.cow/index.htm".
Correct
After clicking in FF, location bar in browser shows
"www.moo.cow/index.htm#moo".
Incorrect. I just tested it.
Can anyone tell me why this should be so?




既然你没有发布ACTUAL代码你正在使用,我将不得不

假设问题在你的代码中。它肯定不存在于你提供的小片段中。

-

最适合所有人的解释性解释可用和虚构的

事实最有可能被阴谋理论家所相信



Since you didn''t post the ACTUAL code you are using, I would have to
assume that the problem is in your code. It certainly doesn''t exist in
the tiny snippet that you provided.
--
"The most convoluted explanation that fits all the available and made-up
facts is the most likely to be believed by conspiracy theorists"


这篇关于处理具有onclick问题的锚点的href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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