我正在使用WordPress
社交媒体插件。当任何用户点击图标时,它会在新选项卡中打开链接,但我希望它在新窗口中,所以为此我使用Javascript
功能
<script type="text/javascript">
// Popup window code
function newPopup(url) {
popupWindow = window.open(
url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
但主要问题是我的代码是用PHP编写的,我不知道如何在其中使用javascript函数。这是我的PHP函数。
$out_button = array(
'tag' => 'a',
'class' => 'synved-social-button synved-social-button-' . $context . ' synved-social-provider-' . $button_key . $class_extra,
'data-provider' => $button_key,
'target' => $button_key != 'mail' ? '_blank' : '',
'rel' => 'nofollow',
'title' => $title,
'href' => $href,
'child-list' => array(
array(
'tag' => 'img',
'alt' => $button_key,
'class' => 'synved-share-image',
'width' => $size,
'style' => 'width:' . $size . 'px;' . $style,
'src' => $image_uri,
)
)
);
'href' => $href,
在这个过程中,我必须编写Javascript
函数,所以我不知道该怎么做。
如果密钥不是邮件,php数组似乎应该将目标设置为_blank。如果你只是设置
'target' => '_blank',
这给了你想要的结果吗?
添加一个onclick事件处理程序怎么样?
onclick = "Some_JavascriptFunction()"
然后在javascript中,您可以使用window.location.href = "someURL.php";