在新窗口中打开 HTML 元重定向

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2852154/
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 03:07:06  来源:igfitidea点击:

Open HTML meta redirect in new window

html

提问by Jeremy Person

I need web page to redirect via HTML meta and open that page in a new window. How can I do that?

我需要网页通过 HTML 元重定向并在新窗口中打开该页面。我怎样才能做到这一点?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Photo Gallery Redirect</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <meta http-equiv="Refresh" content="0; url=http://google.com">
    </head>
    <body>
    </body>
</html>

采纳答案by Mitch Dempsey

You can't. You need to use javascript on a timer to open a popup (which most likely will be blocked by some browsers as an unrequested popup window)

你不能。您需要在计时器上使用 javascript 来打开一个弹出窗口(这很可能会被某些浏览器阻止为未请求的弹出窗口)

You are probably better off taking a different approach to your problem.

您最好采用不同的方法来解决您的问题。

回答by Phil Hudson

You can do this! It is particularly useful when the refresh is being run in an iframe (such as a Facebook app canvas page), and you want the refresh to load the content to the main (parent) window.

你可以这样做!当刷新在 iframe(例如 Facebook 应用画布页面)中运行时特别有用,并且您希望刷新将内容加载到主(父)窗口。

Use the following Javascript in your meta-redirect:

在您的元重定向中使用以下 Javascript:

<meta http-equiv="refresh" content="5; URL=javascript:window.open('http://google.com','_parent');">

回答by BalusC

You can't do that with a meta redirect. Grab JavaScript.

你不能用元重定向来做到这一点。抓取 JavaScript。

<script type="text/javascript">window.open('http://google.com');</script>

Either that, or add target="_blank"to the originating link/form which landed in this "Photo Gallery Redirect" page.

要么,要么添加target="_blank"到在此“照片库重定向”页面中登陆的原始链接/表单。

<a href="http://google.com" target="_blank">click here</a>

or

或者

<form action="http://google.com" target="_blank">
    <input type="submit" />
</form>

Not XHTML/HTML5 valid, but it works. Else you can just add rel="ext"and use some piece of Javascript to silently put the target="_blank"in anyway.

XHTML/HTML5 无效,但它有效。否则,您可以添加rel="ext"并使用一些 Javascript 以静默地将其target="_blank"放入。