javascript - 重定向 onClick + target="_blank"
问题描述
我试图让以下情况发生:
- 用户点击网站上的 img(推特图标/按钮)
- 一个新窗口打开,带有社交分享提示(下面使用的 Twitter URL);当前使用 target="_blank",当然
- 回到其他原始窗口,重定向发生在我网站上的新页面 (freebrandingsurveys.com/instructions) 上,因此,当用户关闭弹出的 target="_blank" 社交共享窗口并返回我的网站时,他们'重新在新的预期页面上。
这是我现在拥有的代码:
<script>
function pageRedirect() {
window.location.href = "https://freebrandingsurveys.com/instructions/";
}
</script>
<a href="https://twitter.com/intent/tweet?url=https://freebrandingsurveys.com" target="_blank" onclick="pageRedirect()">
<img src="twitter.png" alt="Twitter Share"></a>
问题是带有推文的新窗口永远不会打开,而用户只是直接进入网站上的新页面(/instructions)。
以为我可以在重定向上创建某种时间延迟(就像提到的这里),但它不起作用。关于如何实现这一点的任何见解?
解决方案
当用户单击图像时,您希望发生两件事。尝试这个:
<script>
function imgOnClick() {
window.location.href = "https://freebrandingsurveys.com/instructions/"; // navigate to new page in current window
window.open('https://twitter.com/intent/tweet?url=https://freebrandingsurveys.com', '_blank'); // open the twitter page on a new window
}
</script>
<img src="twitter.png" alt="Twitter Share" onclick="imgOnClick()">
推荐阅读
- http - 用户名密码在 URL 中的作用是什么?
- javascript - 谷歌地图不显示,HTML
- kubernetes - 使用 Bastion SSH 到 Kubernetes pod
- karate - 如何在空手道中参数化来自詹金斯的黄瓜选项标签
- c++ - Opencv 从缓冲区写入和读取
- javascript - 用值初始化 Guard
- javascript - Chrome [VM] 文件在每次加载时创建事件处理程序
- python - 计算熊猫数据框中的摘要行
- php - mysqli_fetch_assoc() 在响应版本中不返回任何内容
- php - preg_replace 用于字符串中的“phpbb”报价和颜色标签