简体   繁体   English

如何使用标签 API?

[英]How do I use the tabs API?

I am creating a program that needs to interact with other tabs on the window that the HTML file is opened on, and I found this code.我正在创建一个程序,该程序需要与打开 HTML 文件的 window 上的其他选项卡进行交互,并且我找到了此代码。 However, I think that I have implemented it incorrectly as it does nothing.但是,我认为我没有正确实施它,因为它什么也没做。 Here is my (incomplete) code:这是我的(不完整的)代码:

HTML: HTML:

<html lang="en">

<head>

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Workench</title>

    <script src="dependencies/index.js"></script>
    <link rel="stylesheet" href="dependencies/index.css">

</head>

<body>

    <nav id="toolbar">

        <div id="file">

            <label>File</label>

            <br>

            <button onclick="toolbar.file.saveDoc()">Save</button>
            <button onclick="toolbar.file.newDoc()">New</button>
            <button onclick="toolbar.file.loadDoc()">Load</button>

        </div>

        <div id="upload">

            <label>Upload</label>

            <br>

            <button onclick="toolbar.upload.seasaw()">Seasaw</button>
            <button onclick="toolbar.upload.googleClassroom()">Google Classroom</button>

        </div>

    </nav>

</body>

JavaScript: JavaScript:

import "browser";

const toolbar = {

    file : {

        saveDoc () {

            browser.tabs.create({url: "docs.google.com"}).then(() => {
                browser.tabs.executeScript({
                  code: "console.log('hello');"
                });
              });

        },

        newDoc () {

            

        },

        loadDoc() {

            

        }

    }

};

Any help would be appreciated: :)任何帮助,将不胜感激: :)

For context, this is for my school.就上下文而言,这是针对我的学校的。 It needs to essentially be a text editor that then automatically uploads the text to the platforms that my school uses.它本质上需要是一个文本编辑器,然后自动将文本上传到我学校使用的平台。

The problem is that docs.google.com has not provided you permission for this, see the page you have shared问题是 docs.google.com 没有为您提供此权限,请参阅您共享的页面

在此处输入图像描述

You will need to make sure you have host permissions for the URLs you intend to interact with.您需要确保您对要与之交互的 URL 具有主机权限

I advise you to first try this with pages of the same domain opened in a new tab and when that works, you may venture into the usage with different domains.我建议您首先尝试在新选项卡中打开同一域的页面,然后尝试使用不同的域。

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

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