Edit this page

up.link up:link:follow
DOM event

This event is emitted when a link is followed through Unpoly.

The event is emitted on the <a> element that is being followed.

Changing render options

Listeners may inspect and manipulate render options for the coming fragment update.

The code below will open all form-contained links in an overlay so as not to lose the user's form data:

up.on('up:link:follow', function(event, link) {
  if (link.closest('form')) {
    event.renderOptions.layer = 'new modal'
  }
})

When changing render options for a preloaded link, consider making the same change for up:link:preload so the preload request sends the same HTTP headers.

In the example above, we want to ensure an X-Up-Mode: modal header is sent, so we modify both events:

up.on('up:link:follow up:link:preload', function(event, link) {
  if (link.closest('form')) {
    event.renderOptions.layer = 'new modal'
  }
})

Event properties

event.target
required

The link element that will be followed.

event.renderOptions
required

An object with render options for the coming fragment update.

Listeners may inspect and modify these options. It is recommended that render options for up:link:preload be changed in the same way.

event.preventDefault()
required

Prevents the link from being followed.