所以我想知道如何编写一个按钮来打开2个url。我看到retailmanot.com在点击"获得交易"按钮时这样做。它打开了一个新的标签,里面有他们自己网站上的文章,但在原来的标签上,它打开了交易网站的链接。例如,点击此处的"获取交易"http://www.retailmenot.com/view/bestbuy.com
所以我的代码是
<!-- Author -->
<span class="mix-author"></span>
<a attr="<?php echo $item->author_email; ?>" href="<?php echo $website_url; ?>" target="_blank" style="background-color: grey;padding: 5px 7px;border-bottom: 4px ;border-radius: 4px;float: right;color: white;" >GET DEAL</a>
<?php } ?>
上面的代码在一个新的选项卡中打开。但我希望它在当前选项卡中打开,而我希望下面的代码(链接)在新选项卡中打开而不在单击上面的"获取交易"时显示标题。
<?php if ($params->get('show_title')) { ?>
<!-- Title -->
<h3>
<a href="<?php echo $item->link; ?>" class="mix-title"><?php echo $item->main_title; ?></a>
</h3>
<?php } ?>
请帮帮我。
我认为您需要编写一个javascript函数来同时执行这两项功能,并在点击按钮时被调用:
function twoLinks(same_page_url, new_window_url)
{
window.location = same_page_url; // this will open in the current window
window.open(new_window_url); // this will open in a new window
}
然后从你的链接中这样称呼它:
<a attr="<?php echo $item->author_email; ?>" href="javascript:void(0);" onclick="twoLinks('<?php echo $website_url; ?>', '<?php echo $new_window_url; ?>');" style="background-color: grey;padding: 5px 7px;border-bottom: 4px ;border-radius: 4px;float: right;color: white;" >GET DEAL</a>
我借用了这个答案的一部分:
jQuery:使用target="_空白";
关于你的进一步评论,当我尝试你的代码时,一切都如预期的那样对我有效。检查浏览器中的html,您的GET DEAL
链接应该包含以下内容:
<a attr="" href="javascript:void(0);" onclick="twoLinks('http://www.arg.is', 'http://www.google.com');" style="background-color: grey;padding: 5px 7px;border-bottom: 4px ;border-radius: 4px;float: right;color: white;">GET DEAL</a>
我需要看到错误消息和/或你的链接的html来帮助你。我在想:
- 您没有像我一样包含
http://
部分,并且您的链接正在尝试服务器上不存在的相对路径 - 您打印到函数参数中的一个变量不是它应该是的