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

如何避免Bookmarklet打开额外的空白标签页?

如何避免Bookmarklet打开额外的空白标签页?

嘿,我之前也碰到过一模一样的情况!你的书签小工具逻辑本身没毛病,但当你从书签文件夹批量打开时,浏览器会把脚本的返回值当成新页面内容来加载,这就蹦出那个讨厌的空白标签了。

问题出在window.open()上——这个方法执行后会返回新打开窗口的引用对象,浏览器拿到这个返回值,就会默认生成一个新标签页来显示它(也就是你看到的空白页)。

解决方法很简单,只需要让你的脚本不返回任何有效值就行,有两种常用的方式:

  • 方式一:在window.open()前面加上void运算符,它会把表达式的返回值转为undefined,浏览器就不会乱创建标签了:

    javascript: (() => {  
      const det = "https://comicskingdom.com/candorville/"; 
      const today = new Date();
      const year = today.getFullYear();
      const month = String(today.getMonth() + 1).padStart(2, '0');
      const day = String(today.getDate()).padStart(2, '0');
      const formattedDate = `${year}-${month}-${day}`;
      void(window.open(det+formattedDate));  
    })();
    
  • 方式二:在脚本的最后一行加上void 0;或者return;,直接终止脚本的返回值:

    javascript: (() => {  
      const det = "https://comicskingdom.com/candorville/"; 
      const today = new Date();
      const year = today.getFullYear();
      const month = String(today.getMonth() + 1).padStart(2, '0');
      const day = String(today.getDate()).padStart(2, '0');
      const formattedDate = `${year}-${month}-${day}`;
      window.open(det+formattedDate);
      void 0;
    })();
    

你可以选其中一种改,之后再从书签文件夹批量打开,就只会看到你想要的漫画页面,不会有多余的空白标签啦!

备注:内容来源于stack exchange,提问作者geoB

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 13:53:03