如何在新窗口中打开

how to open in new window

本文关键字:在新窗口中打开      更新时间:2023-09-26

>我还有另一个问题:(这是我的脚本

<script type="text/JavaScript">
    function first()
    {
        var first = confirm("Are you sure you want to navigate away from this page?");
            if (first)
                window.location = "http://www.yahoo.com.sg"
            else
            window.close;
    }
    function second()
    {
        var second = confirm("Are you sure you want to navigate away from this page?");
        if (second)
            window.location = "http://www.google.com"
        else
            window.close;
    }
</script>

<p><b>Click the following link to enter yahoo</b></p>
<p><a href="javascript:first()"title="Opens in an external website in a new window">yahoo</a></p>
<p><b>Click the following link to check google</b></p>
<p><a href="javascript:second()" title="Opens in an external website in a new window">google</a></p>

它不会在新窗口中打开。请我需要一些帮助。有什么建议或建议吗?

尝试window.open .这将打开一个新窗口:

window.open("http://www.google.com");

另请参阅:

  • MDN:window.open可用性问题

使用 window.open 方法并指定_blank作为目标:

window.open('http://www.yahoo.com.sg', '_blank');

这将在新窗口或新选项卡中打开页面,具体取决于浏览器中的用户设置。

如果希望它始终在新弹出窗口中打开,则可以为窗口指定具有宽度和高度的参数字符串。但是,大多数浏览器会阻止从其他域打开页面的此类弹出窗口。

如果要在新窗口中打开,则无需与用户确认是否导航离开。

function first()
    {
           window.open("http://www.yahoo.com.sg")
    }
    function second()
    {
        window.open"http://www.google.com")
    }