在访问链接之后,Firefox有选择地跳过状态更改或访问样式 [英] After visiting links, Firefox selectively skips state change or a:visited styling

查看:142
本文介绍了在访问链接之后,Firefox有选择地跳过状态更改或访问样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击一个具有常见href(本地页面或网站)
的链接,并且href被成功加载后,FF2和IE7将显示带有:visited样式的链接



对于带有href =javascript:anyfunc()的链接,IE7按照
的方式工作,而FF2不显示:visited样式。
DOCTYPE没有任何变化。

问题:JS链接和:visited中的行为是否被认为是正确的?


$ b $问:FF2在单击JS链接后是否保持锚状态不变?



Q:无需附加onClick处理程序或修改类/样式
与JS,是否有一个简洁的方式告诉FF2使用:visted
风格独立于href是另一个页面还是一个JS链接?

例子如下:

 < html> 
< head>
< style>
div.links {font-size:18px; }
div.links a {color:black;文字修饰:无; }

div.links a:visited {background-color:purple;颜色:黄色; }
div.links a:hover {background-color:yellow;颜色:黑色; }
< / style>

< script>
函数tfunc(info){alert(tfunc:info =+ info)}
< / script>
< / head>
< body>

< div class =links>
< a href =javascript:tfunc(10)> JS Link 1< / a>< br>
< a href =javascript:tfunc(20)> JS Link 2< / a>< br>
< a href =http://www.google.com/>常见的href,google< / a>
< / div>

< / body>
< / html>


解决方案

我遇到了这个问题, 。考虑这个简单的例子:

样式表:

$ $ $ $ $ $ $ $ $# display:none;}
#contactbox {display:none; }

html:

 < a id =#home>< / a> 
< a href =#homeonclick =return showHideDiv(this);>显示首页< / a>
< div id =homebox>您的家< / div>
< a id =#contact onclick =return showHideDiv(this);>< / a>
< div id =contactbox>联络资讯< / div>

script:

  function showHideDiv(elem){
if(elem.style.display& elem.style.display ==none;)elem.style.display =block;
else if(elem.style.display& elem.style.display ==block;)elem.style.display =none;
return true;
}

虽然不是最漂亮的代码,但它指出了在href中使用javascript onlick时可能会出现的一些问题。你可能想要这样做的原因是创建动态内容更改而不重新显示访问的样式a链接比按钮更加便于链接的访问状态即使在内部也保持不变已经注意到浏览器触发内部链接访问状态的一些问题,更不用说与jav的内部链接了ascript onclick事件处理程序。一个按钮需要编写一个函数来控制访问的样式。


After clicking a link with a common href (local page or web-site) and the href is successfully loaded, both FF2 and IE7 will display the link with a:visited styling.

For links with href="javascript:anyfunc()", IE7 works as above while FF2 does not display a:visited styling. No change with any DOCTYPE.

Q: Is either behaviour with JS links and :visited considered correct?

Q: Does FF2 leave anchor state unchanged after clicking a JS link?

Q: Without having to attach an onClick handler or modify classes/style with JS, is there a concise way to tell FF2 to use :visted styling independent of whether href is another page or a JS link?

Example follows:

<html>
<head>
<style>
div.links { font-size: 18px; }
div.links a { color: black; text-decoration: none; }

div.links a:visited { background-color: purple; color: yellow; }
div.links a:hover { background-color: yellow; color: black; }
</style>

<script>
function tfunc(info) { alert("tfunc: info = " + info) }
</script>
</head>
<body>

<div class="links">
    <a href="javascript:tfunc(10)">JS Link 1</a><br>
    <a href="javascript:tfunc(20)">JS Link 2</a><br>
    <a href="http://www.google.com/">Common href, google</a>
</div>

</body>
</html>

解决方案

I have encountered the issue I believe this question is asking. Consider this simple example:

style sheet:

#homebox { display: none;}
#contactbox { display: none; }

html:

<a id="#home"></a>
<a href="#home" onclick="return showHideDiv(this);">Show Home</a>
<div id="homebox">Your home</div>
<a id="#contact onclick="return showHideDiv(this);"></a>
<div id="contactbox">Contact Info</div>

script:

function showHideDiv(elem) {
if( elem.style.display && elem.style.display == "none"; ) elem.style.display = "block";
else if( elem.style.display && elem.style.display == "block"; ) elem.style.display = "none";
return true;
}

Although not the most beautiful code, it points out some issues which can develop when using javascript onlick within a href. The reason you might want to do something like this, is to create dynamic content changes without reload which show a visited style. The a links would be handier than buttons, so the visited status of the links is maintained, even though internal. However, I have noticed some issues with browsers triggering visited status on internal links, let alone internal links with javascript onclick event handlers. A button would require coding a function to control visited styles.

这篇关于在访问链接之后,Firefox有选择地跳过状态更改或访问样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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