我有一个页面使用spin.js(http://fgnass.github.io/spin.js/#!)纯Javascript微调器来显示一个微调器,当点击一个链接(慢速页面)。我在链接上使用onclick触发它。
问题出现在Chrome(v 30.0.1599.69 m)中,如果我在中间按钮上单击链接以在新选项卡中打开慢速页面,那么当我返回到原始页面时,微调器正在运行并且一直运行。它不会发生在IE或Firefox中。
(显然,如果我左键单击链接,则在加载新页面时,微调器将会死亡。)
我的链接如下:<a href="other-sources.php?id='.$id.'" onClick="return spinner(40);">Other Sources</a>
启动微调器的脚本如下所示:
<script type="text/javascript">
// Display spinner while waiting for Other Sources to display.
// Parameter is vertical position of spinner, since we have 2 Show Source links
function spinner(posn) {
var opts = {
lines: 15, // The number of lines to draw
length: 7, // The length of each line
width: 4, // The line thickness
radius: 15, // The radius of the inner circle
corners: 1, // Corner roundness (0..1)
rotate: 0, // The rotation offset
color: '#000', // #rgb or #rrggbb
speed: 1, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: 'spinner', // The CSS class to assign to the spinner
zIndex: 2e9, // The z-index (defaults to 2000000000)
top: posn, // Top position relative to parent in px
left: 850 // Left position relative to parent in px
};
var target = document.getElementById('main');
var spinner = new Spinner(opts).spin(target);
return true;
}
</script>
为了完成图片,我在Head部分有这个:
<script src="spin.min.js"></script>
我可以在javascript中放置一些内容来忽略中间按钮点击吗?我在别处读到检测按钮是相当古怪的。
嗯。我看到有一个关于它的错误报告可以追溯到2008年:https://code.google.com/p/chromium/issues/detail?id=1687
好的,我解决了以下问题:
if (event.which == null)
/* IE case */
var button= (event.button < 2) ? "LEFT" :
((event.button == 4) ? "MIDDLE" : "RIGHT");
else
/* All others */
var button= (event.which < 2) ? "LEFT" :
((event.which == 2) ? "MIDDLE" : "RIGHT");
if (button != "LEFT")
return true;