JS的最佳实践 - 在href或onclick中的window.open()? [英] Best Practice for JS - window.open() in href or in onclick?
本文介绍了JS的最佳实践 - 在href或onclick中的window.open()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
关于优化的问题,在:
<a href="#" onClick="javascript:window.open('myUrl.com');">link-1</a>
和:
<a href="javascript:window.open('myUrlBis.com');">link-2</a>
一个比另一个好吗?还是更兼容?谢谢。
Is one better than the other ? Or more compatible ? Thanks.
推荐答案
最佳做法是使用 目标
属性:
Best practice is to use the target
attribute:
<a href="http://myUrl.com" target="_blank">link-1</a>
如果不适合,点击
处理程序(理想情况下不通过属性分配)将是我的选择。
If that doesn't suit, a click
handler (ideally not assigned via attribute) would be my take.
这篇关于JS的最佳实践 - 在href或onclick中的window.open()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文