简体   繁体   English

Google Chrome 扩展 JS 没有按预期显示 function

[英]Google Chrome extension JS doesn't function as expected

I want to change the default behavior of the hyperlink on Google Sheets.我想更改 Google 表格中超链接的默认行为。 It's currently opening hyperlinks in a new tab in a new tab.它目前正在新选项卡中的新选项卡中打开超链接。 What I want to do is, to open them on a popup window.我想要做的是,在弹出窗口 window 上打开它们。

在此处输入图像描述

As there's no target option for the default HYPERLINK() function of sheets, I decided to go with a Chrome Extension.由于默认的HYPERLINK() function 工作表没有target选项,我决定使用 Chrome 扩展程序 go。 Here's how it looks like:它是这样的:

Manifest.json

{
  "manifest_version": 2,
  "name": "Google Sheets Clicker",
  "version": "0.1",
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "content_scripts": [
  {
    "matches": [
      "https://docs.google.com/spreadsheets*"
    ],
    "js": ["jq.js", "content.js"]
  }

]
}

And the content.js (for testing purposes, I'm just alerting the url)content.js (出于测试目的,我只是提醒 url)

$(document).ready(function(){
   $('body').on('click', 'a', function(){
     var url = $(this).attr('href');
     alert(url);
     return false;
   });
});

But it's not triggering the function when the hyperlink get's clicked on the sheets window.但是当在工作表 window 上单击超链接时,它不会触发 function。

What am I doing wrong?我究竟做错了什么?

Instead try to just jquery the href html tag $("a").on("click",....)而是尝试仅 jquery href html 标签 $("a").on("click",....)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM