blob: 90c045d86b0f9c7441c587959246da1aeff22b49 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
---
title: contentScripts.RegisteredContentScript.unregister()
slug: >-
Mozilla/Add-ons/WebExtensions/API/contentScripts/RegisteredContentScript/unregister
tags:
- API
- Extensions
- Reference
- RegisteredContentScript.unregister
- contentScripts
translation_of: >-
Mozilla/Add-ons/WebExtensions/API/contentScripts/RegisteredContentScript/unregister
---
<div>{{AddonSidebar()}}</div>
<div>Annule l'inscription des scripts de contenu représentés par cet objet <code>RegisteredContentScript</code>.</div>
<h2 id="Syntaxe">Syntaxe</h2>
<pre class="syntaxbox brush:js">registered.unregister()
</pre>
<h3 id="Paramètres">Paramètres</h3>
<p>None.</p>
<h3 id="Valeur_retournée">Valeur retournée</h3>
<p>None.</p>
<h2 id="Compatibilité_du_navigateur">Compatibilité du navigateur</h2>
<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
<p>{{Compat("webextensions.api.contentScripts.RegisteredContentScript.unregister", 10)}}</p>
<h2 id="Exemples">Exemples</h2>
<p>Ce code permet de basculer un script de contenu enregistré sur un clic d'action du navigateur :</p>
<pre class="brush: js">var registered = null;
async function register() {
registered = await browser.contentScripts.register({
matches: ["*://*.org/*"],
js: [{
code: "document.body.innerHTML = '<h1>This page has been eaten<h1>'"
}],
runAt: "document_idle"
});
}
function toggle() {
if (registered) {
registered.unregister();
registered = null;
} else {
register();
}
}
browser.browserAction.onClicked.addListener(toggle);
</pre>
<p>{{WebExtExamples}}</p>
|