为什么不能正常使用href =“ javascript”?

时间:2019-09-04 01:30:47

标签: javascript google-chrome

Chrome浏览器

버전:Mozilla / 5.0(Windows NT 10.0; Win64; x64)AppleWebKit / 537.36(KHTML,如Gecko)Chrome / 76.0.3809.132 Safari / 537.36

点击链接

<!DOCTYPE html>
<html>
<body>
<script>
function winopen(url){
    window.open(url, '_blank');
    }
</script>
<p>Open link in a new window or tab: <a href="javascript:winopen('https://www.w3schools.com');" target="_blank">Visit W3Schools!</a></p>

</body>
</html>

O:https://www.w3schools.com窗口打开
X:关于:空白窗口打开

1 个答案:

答案 0 :(得分:0)

我猜您正在尝试在空白窗口中打开链接? 如果您尝试更改href,使其直接指向链接。

HTML

    <!DOCTYPE html>
<html>

<body>
    <script>
        function winopen(url) {
            window.open(url, '_blank');
        }
    </script>
    <p>Open link in a new window or tab: <a href="https://www.w3schools.com" target="_blank">Visit W3Schools!</a></p>

</body>

</html>