You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

点击事件触发多链接打开问题:跳转指定页同时打开新标签

Fix for Opening Multiple Tabs + Current Tab Navigation

The issue with your existing code is that the browser's default link navigation (triggered by the href attribute) can interfere with the window.open calls—browsers often block popups that occur alongside a main navigation, as they might be perceived as unwanted. Here's how to fix it:

Corrected Code

HTML

<a id="mybutton" href="http://example.net/quote" onclick="url_open(event)">See Offer</a>

JavaScript

function url_open(event) {
  // Stop the default link behavior from running immediately
  event.preventDefault();
  
  // Open the two secondary URLs in new tabs
  window.open("http://example.net/events", "_blank");
  window.open("http://example.net/gallery", "_blank");
  
  // Navigate the current tab to the main URL
  window.location.href = "http://example.net/quote";
  
  alert('Check The Tabs');
}

Why This Works

  1. event.preventDefault(): This stops the browser from immediately navigating to the href URL, removing the conflict with popup calls.
  2. Explicit Navigation: By using window.location.href to navigate the current tab after opening popups, we ensure all actions are explicitly tied to the user's click event, avoiding popup blocking.
  3. User-Initiated Actions: All window.open calls are directly within the click handler, so browsers recognize them as intentional user actions (not automated popups) and allow them (assuming the user hasn't blocked popups for your site).

Note: Make sure your site is allowed to open popups in the user's browser—most browsers will prompt the user the first time, so they'll need to grant permission.

内容的提问来源于stack exchange,提问作者JeVic

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:47:26