---
title: External Link Question
description: Asks before a link takes the reader to another site, names the host and the whole address, and leaves trusted hosts alone.
visibility: guest
draft: false
---

# External Link Question

`<x-wirekit::external-link-question>` asks before a link takes the reader to another site. Place
it once in your layout. A click on any link of the page whose address is another site, one that is
neither the page's own nor trusted, opens an [alert dialog](/components/alert-dialog): its title
names the host, and under a sentence on disguised addresses it shows the whole address the browser
would open. The reader stays, or visits the site.

<!-- markdownlint-disable MD034 -->
:::preview{title="A link to another site asks first" navigable}
<x-wirekit::external-link-question :trusted="['wirekit.app']" />
<x-wirekit::stack gap="sm">
<x-wirekit::link href="https://laravel.com/docs/eloquent-relationships#eager-loading" external>The Laravel documentation asks first</x-wirekit::link>
<x-wirekit::link href="https://wirekit.app" external>The WireKit website, a trusted host, opens without a question</x-wirekit::link>
</x-wirekit::stack>
:::
<!-- markdownlint-enable MD034 -->

Every link of the page asks, not only a [link component](/components/link): an anchor of your own, a button
written as one, a link in rendered Markdown, the area of an image map. A plain click, a click with a key that opens another
tab or window, and a click of the middle button all ask, and Visit then opens the site the way that
click would have: in this window, in the window above a frame for `target="_top"` or `"_parent"`,
or in a new tab, which opens with `noopener` and `noreferrer`. A link to a window it names by a
name of its own opens a new tab as well. A link that decides its referrer itself, with
`rel="noreferrer"` or a `referrerpolicy` of its own, keeps that decision in this window and in the
window above a frame. Stay closes the dialog and leaves the focus on the link.

The question for the middle button is a progressive enhancement: it asks where the browser reports
that click as `auxclick`, which Safari does from 18.2 on.

## Usage

One question serves the whole page, so it goes into your layout, beside the content:

```blade
{{-- resources/views/components/layouts/app.blade.php, or the layout your pages use --}}
<body>
    {{ $slot }}

    <x-wirekit::external-link-question />
</body>
```

Its script comes with WireKit's bundle: `@wirekitScripts` loads it with the default `full` bundle, and with `auto` and `csp`.

## The Address the Browser Opens

The dialog shows the address as the browser reads it, which is what makes a disguised one visible:

- **A user name before the `@`.** In `https://example.com@login.example.net/`, the part
  before the `@` is a user name, and the site is `login.example.net`. The title names that host,
  and the address shows the whole line.
- **A host in other characters.** A host written with characters outside ASCII reaches the browser
  as its punycode, `xn--…`. The address shows the punycode, and a line under it names the host as
  the link writes it, so a host that only looks like another one stands beside the host it really is.

A long address breaks at its seams, the same ones as in [`<x-wirekit::text break="address">`](text.md#breaking-an-address): before the `@`, a full stop, a hyphen or a slash, so a narrow dialog never splits a host between two of its letters. Only a part longer than the line breaks inside.

`mailto:`, `tel:` and every other address that opens no site are left alone, and so is a link
with `download`.

## Trusted Hosts

The page's own host never asks. Your own services, and the addresses a customer owns, should not
ask either. Name them in the configuration, for every page:

```php
// config/wirekit.php
'components' => [
    'external-link-question' => [
        'trusted' => ['pushery.com', '*.pushery.com'],
        'remember' => 'browser',
    ],
],
```

A host is matched as it is, or, written with a leading `*.`, together with every host under that
domain and the domain itself: `*.pushery.com` trusts `pushery.com`, `docs.pushery.com` and
`api.docs.pushery.com`. A host may be written in its own characters or in its punycode:
`müller.de` and `xn--mller-kva.de` name the same host. An entry written as an address names its
host: `https://example.com/guide` and `example.com:8443` both trust `example.com` on every port, as
the page's own host never asks, whatever the port. Hosts that are known only per request, such as the addresses of the
customer whose page this is, go into the `trusted` prop, beside the configuration's:

```blade
<x-wirekit::external-link-question :trusted="$tenant->domains" />
```

A script can trust more hosts while the page stands, with an event on `window`:

```js
window.dispatchEvent(new CustomEvent('wirekit:external-links-trust', {
    detail: { hosts: ['status.example.com'] },
}));
```

And a single link trusts itself with `data-wk-trusted`, as does every link inside an element that
carries it.

## Not Warning Again

Under the address, a checkbox offers not to warn about links to this host again. Checked, Visit
keeps the host, and `remember` says where:

| `remember` | Kept |
| --- | --- |
| `browser` | In the browser's local storage, for every page of the site in this browser. The default. |
| `none` | Nowhere. The choice holds while the page stands. |

Either way the component dispatches `wirekit:external-link-trusted` on `window`, with the host in
its detail. An application that keeps the choice per user, on every device the user signs in on,
stores the host there and passes it back in `trusted`:

```js
window.addEventListener('wirekit:external-link-trusted', (event) => {
    Livewire.dispatch('trust-host', { host: event.detail.host });
});
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `trusted` | `array` | `[]` | Hosts that never ask, beside the configuration's `trusted`. A host as it is, or `*.example.com`. |
| `remember` | `browser\|none` | `browser` | Where a host the reader chose not to be warned about again is kept. |
| `scope` | `string\|null` | `null` | Scoped personalization name |

## Events

| Event | On | Detail | When |
| --- | --- | --- | --- |
| `wirekit:external-links-trust` | `window` | `{ hosts: string[] }` | Your script sends it to trust more hosts while the page stands. |
| `wirekit:external-link-trusted` | `window` | `{ host: string }` | The component sends it when the reader visits a host with the checkbox checked. |

## Accessibility

- The question is an alert dialog: the title names it, and the sentence describes it.
- Stay has the focus when the dialog opens, and Escape does what Stay does.
- However the dialog closes, the focus stands on the link again.

## Keyboard Interaction

| Key | Action |
|-----|--------|
| `Enter` (on a link to another site) | Asks the question instead of opening the site, as a click does |
| `Tab` / `Shift+Tab` | Moves through the checkbox, Stay here and Visit site; the focus stays in the dialog |
| `Space` (on the checkbox) | Checks or unchecks "Don't warn me about links to … again" |
| `Enter` (on a focused button) | Presses it: Stay here closes the dialog, Visit site opens the site |
| `⌘ Enter` / `Ctrl+Enter` | Presses Visit site, as in every [alert dialog](/components/alert-dialog#confirming-from-the-keyboard) |
| `Escape` | Does what Stay here does |

## See Also

- [Link component](/components/link): `external` marks a link that opens another site in a new tab.
- [Alert Dialog](/components/alert-dialog): the dialog the question is asked in.
- [Unsaved Hint](/components/unsaved-hint): the question before leaving a form with unsaved fields.
