Html Javascript 重定向 - 新窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15207898/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 06:07:30  来源:igfitidea点击:

Javascript redirect - New Window

javascripthtmliframe

提问by user2132731

I'm trying to create a re-direct using Javascript from inside a blank iframe that will direct to a URL inside a new window or tab.

我正在尝试使用 Javascript 从空白 iframe 中创建重定向,该 iframe 将定向到新窗口或选项卡中的 URL。

More specifically, I'm trying to make a Facebook tab point to my company's webpage rather than load the page inside the tab's iframe which is not the same width as our web page.

更具体地说,我试图让 Facebook 标签指向我公司的网页,而不是在标签的 iframe 内加载页面,该 iframe 与我们的网页宽度不同。

Here is the redirect script I already have but it doesn't open the URL in a new window.

这是我已有的重定向脚本,但它不会在新窗口中打开 URL。

<script language="JavaScript">
<!--Redirect to 75th page
var time = null
function move() {
window.location = 'http://philmontscoutranch.org/Camping/75.aspx'
}
timer=setTimeout('move()',0000)
//-->
</script>


Ok - This snippet will open a new window when the page loads but Chrome's pop-up blocker blocked it. I didn't think about this until now. Maybe I could have it load in a light window?

好的 - 此代码段将在页面加载时打开一个新窗口,但 Chrome 的弹出窗口阻止程序阻止了它。直到现在我才想到这个。也许我可以把它放在一个明亮的窗户里?

<script language="JavaScript">
<!--Redirect to 75th page
var time = null
function open_win()
{
window.open("http://philmontscoutranch.org/Camping/75.aspx", "_blank");
}

timer=setTimeout('open_win()',0000)
//-->
</script>

回答by Zachrip

Here you go: Jsfiddle Example

给你:Jsfiddle 示例

function opennewtab(url){
    var win = window.open(url, '_blank');
}

回答by yMed

<html>
<head>
<script>
function open_win()
{
window.open("http://philmontscoutranch.org/Camping/75.aspx", "_blank");
}
</script>
</head>
<body>
<input type="button" value="Open Window" onclick="open_win()">
</body>
</html>

Source

来源