Leaving preview confirmation not working if clicked link contains markup

Created on 24 April 2024, 8 months ago

Problem/Motivation

In node preview mode, when clicking on any link, a modal dialog opens to prevent leaving the page in preview mode and loosing changes.

Confirming to leave the preview in the modal does not work, when the link clicked contains HTML markup instead of plain text, and the current location get re-written incorrectly (node/preview/[UUID]/undefined instead of the href value of the clicked link).

Steps to reproduce

  • Enable preview mode for any node type of a Drupal standard installation.
  • Edit a node and then click on preview.
  • Click on any link (i. e. in the administration menu) and then on the "Leave preview" button.
  • Check the browser address bar after the redirect.

Proposed resolution

clickPreviewModal() of Drupal.behaviors.nodePreviewDestroyLinks uses the event.target property to update the current location:

window.top.location.href = event.target.href;

This works if the link clicked only contains plain text, but not if it contains any HTML markup like span, em or strong. This is due to

The read-only target property of the Event interface is a reference to the object onto which the event was dispatched. It is different from Event.currentTarget when the event handler is called during the bubbling or capturing phase of the event. (MDN – Event: target property)

Therefore, I recommend using event.currentTarget instead.

🐛 Bug report
Status

Active

Version

10.2

Component
Node system 

Last updated 4 days ago

No maintainer
Created by

🇦🇹Austria mvonfrie

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024