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, as to not 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 a X-Up-Mode: modal header to be 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 Element

The link element that will be followed.

event.renderOptions Object

An object with render options for the coming fragment update.

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

event.preventDefault()

Prevents the link from being followed.