Html 加载时,在新选项卡/窗口中重定向页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6216743/
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
On load, redirect page in new tab/window
提问by Rob
I have access to a page template but no access to the header template (don't ask me how!), I need to create an instant page redirect on that template. It's needs to open in a new window.
我可以访问页面模板但无法访问标题模板(不要问我如何!),我需要在该模板上创建即时页面重定向。它需要在新窗口中打开。
It doesn't really matter how it's done just that it opens in a new window and please bear in mind I don't have access to the header template.
它是如何完成的并不重要,只是它会在新窗口中打开,请记住,我无权访问标题模板。
回答by Terrance
I could be a bit off here (please correct me if i am) but,
you just the page to open a new page then something like this
See this for detailed usage of window.open.
You can pass html into the function as well.
我可能在这里有点偏离(如果我是,请纠正我)但是,
您只是打开一个新页面的页面,然后是这样的,
请参阅this了解window.open的详细用法。
您也可以将 html 传递到函数中。
<body onload="window.open(yourwindow)">
<body onload="window.open(yourwindow)">
Or if you were just wanting a redirect to an existing page then
See this for detailed usage of window.location.
或者,如果您只是想重定向到现有页面,
请参阅此处了解 window.location 的详细用法。
<body onload=window.location='www.yourlocation.com'>
<body onload=window.location='www.yourlocation.com'>
Pass that whatever you want for parameters into the url.
将您想要的任何参数传递到 url 中。
Or if you were looking to grab some info from the page before you transition then you could just write a function that grabs the data you need from the header and pass that to the new page.
或者,如果您想在转换之前从页面中获取一些信息,那么您可以编写一个函数,从标题中获取所需的数据并将其传递给新页面。