aboutsummaryrefslogtreecommitdiff
path: root/files/pt-pt/mozilla/add-ons/webextensions/user_interface/extension_pages/index.html
blob: bea67ee60c658b0f288df9c76967df6d5f9a1b5b (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
---
title: Páginas de extensão
slug: Mozilla/Add-ons/WebExtensions/user_interface/Extension_pages
translation_of: Mozilla/Add-ons/WebExtensions/user_interface/Extension_pages
original_slug: Mozilla/Add-ons/WebExtensions/interface_do_utilizador/Paginas_de_extensão
---
<div>{{AddonSidebar()}}</div>

<p>Pode inclur páginas html na sua extensão para fornecer formulários, ajuda, ou qualquer outro conteúdo que a sua extensão precisar.</p>

<p><img alt="Example of a simple bundled page displayed as a detached panel." src="https://mdn.mozillademos.org/files/15752/bundled_page_as_panel_small.png" style="display: block; height: 216px; margin-left: auto; margin-right: auto; width: 350px;"></p>

<p>These pages also get access to the same privileged JavaScript APIs that are available to your extension's background scripts.</p>

<h2 id="Especificar_páginas_de_extensão">Especificar páginas de extensão</h2>

<p>You can include HTML files, and their associated CSS or JavaScript files, in your extension. The files can be included in the root or organized within meaningful sub-folders.</p>

<pre>/my-extension
    /manifest.json
    /my-page.html
    /my-page.js</pre>

<h2 id="Exibir_páginas_de_extensão">Exibir páginas de extensão</h2>

<p>There are two options for displaying extension pages: {{WebExtAPIRef("windows.create()")}} and {{WebExtAPIRef("tabs.create()")}}.</p>

<p>Using <code>windows.create()</code>, for example, you can open an HTML page into a detached panel (a window without the normal browser UI of address bar, bookmark bar, and alike) to create a dialog-like user experience:</p>

<pre class="brush: js">var createData = {
  type: "detached_panel",
  url: "panel.html",
  width: 250,
  height: 100
};
var creating = browser.windows.create(createData);</pre>

<p>When the window is no longer needed, it can be closed programmatically, for example, after the user clicks a button, by passing the id of the current window to {{WebExtAPIRef("windows.remove()")}}:</p>

<pre class="brush: js">document.getElementById("closeme").addEventListener("click", function(){
  var winId = browser.windows.WINDOW_ID_CURRENT;
  var removing = browser.windows.remove(winId);
}); </pre>

<h2 id="Páginas_de_extensão_e_histório">Páginas de extensão e histório</h2>

<p>By default, pages you open in this way will be stored in the user's history, just like normal web pages. If you don't want to have this behavior, use {{WebExtAPIRef("history.deleteUrl()")}} to remove the browser's record:</p>

<pre class="comment-text " id="ct-4">function onVisited(historyItem) {
  if (historyItem.url == browser.extension.getURL(myPage)) {
    browser.history.deleteUrl({url: historyItem.url});
  }
}

browser.history.onVisited.addListener(onVisited);</pre>

<p>To use the history API, you must request the "history" <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions">permission</a> in your <code><a href="https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json">manifest.json</a></code> file.</p>

<h2 id="Desenho_da_página_da_Web">Desenho da página da Web</h2>

<p>For details on how to design your web page's to match the style of Firefox, see the <a class="grey-90 no-underline hover-no-underline" href="https://design.firefox.com/photon/index.html">Photon Design System</a> documentation.</p>

<h2 id="Exemplos">Exemplos</h2>

<p>The <a class="external external-icon" href="https://github.com/mdn/webextensions-examples">webextensions-examples</a> repository on GitHub includes the <a class="external external-icon" href="https://github.com/mdn/webextensions-examples/tree/master/window-manipulator">window-manipulator</a> example, which implements several of the options for creating windows.</p>