Javascript 在新标签页中打开页面是否有任何 PHP 函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12796324/
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
is there any PHP function for open page in new tab
提问by suiz
I have a form with action e.g. register.php
我有一个带有操作的表单,例如 register.php
I also have a Google group API link -
我还有一个 Google 群组 API 链接 -
in short... Is there any PHP function for open page in new tab; on page load...
简而言之......在新标签页中打开页面是否有任何PHP函数;在页面加载...
回答by Terry Harvey
Use the target
attribute on your anchor
tag with the _blank
value.
使用带有值target
的anchor
标签上的属性_blank
。
Example:
例子:
<a href="http://google.com" target="_blank">Click Me!</a>
回答by Anoop
You can write JavaScript code in your file .
您可以在文件中编写 JavaScript 代码。
Put following code in your client side file:
将以下代码放在您的客户端文件中:
<script>
window.onload = function(){
window.open(url, "_blank"); // will open new tab on window.onload
}
</script>
using jQuery.ready
使用 jQuery.ready
<script>
$(document).ready(function(){
window.open(url, "_blank"); // will open new tab on document ready
});
</script>
回答by Mr. Alien
You can simply use target="_blank"
to open a page in a new tab
您可以简单地使用target="_blank"
在新选项卡中打开页面
<a href="whatever.php" target="_blank">Opens On Another Tab</a>
Or you can simply use a javascript for onload
或者您可以简单地使用 javascript 进行加载
<body onload="window.open(url, '_blank');">
回答by andydoe
You can use both PHP and javascript. Perform your php codes in the backend and redirect to a php page. On the php page you redirected to add the code below:
您可以同时使用 PHP 和 javascript。在后端执行您的 php 代码并重定向到一个 php 页面。在您重定向的 php 页面上添加以下代码:
<?php if(condition_to_check_for){ ?>
<script type="text/javascript">
window.open('url_goes_here', '_blank');
</script>
<? } ?>
回答by Rohan Khude
This is a trick,
这是套路
function OpenInNewTab(url) {
var win = window.open(url, '_blank');
win.focus();
}
In most cases, this should happen directly in the onclick handler for the link to prevent pop-up blockers, and the default "new window" behavior. You could do it this way, or by adding an event listener to your DOM object.
在大多数情况下,这应该直接在链接的 onclick 处理程序中发生,以防止弹出窗口阻止程序和默认的“新窗口”行为。您可以通过这种方式或通过向 DOM 对象添加事件侦听器来实现。
<div onclick="OpenInNewTab();">Something To Click On</div>