diff --git a/Documentation/Report.rst b/Documentation/Report.rst index 520f1a4e0f46146954552fa11eaae2c9c01eb8f2..5bcadd94b8c05a710001f2f02ec386685d43111a 100644 --- a/Documentation/Report.rst +++ b/Documentation/Report.rst @@ -1056,6 +1056,16 @@ Text before / after link } +.. _ignoreHistory: + +Ignore/Skip browser history +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +To ignore/skip adding a browser history entry when clicking on a link, add the attribute `data-ignore-history`:: + + 'data-ignore-history' + Example: 10.sql = SELECT 'p:{{pageSlug:T}}?form=test_form&r=2&variable1=test|s|b|t:Button|A:data-ignore-history' AS _link + .. _column_pageX: diff --git a/javascript/src/Main.js b/javascript/src/Main.js index 694165c2d6b7c68092a3c1c13126b94e54de4ced..c01bcbe92306fd428521c7dd187a219620484a54 100644 --- a/javascript/src/Main.js +++ b/javascript/src/Main.js @@ -205,8 +205,44 @@ $(document).ready( function () { }); }; + n.initializeIgnoreHistoryBtn = function () { + // Attaching the event listener to the document + document.addEventListener('click', function(event) { + var element = event.target; + + // Traverse up to find the element with 'data-ignore-history' + while (element && !element.hasAttribute('data-ignore-history')) { + element = element.parentNode; + if (element === document) { + return; // Exit if reached the document without finding the target + } + } + + if (element) { + handleIgnoreHistoryClick(event, element); + } + }); + }; + + function handleIgnoreHistoryClick(event, element) { + event.preventDefault(); + let alertButton = document.querySelector('.alert-interactive .btn-group button:first-child'); + let url = element.href; + + if (alertButton) { + alertButton.onclick = function() { + if (url) { + window.location.replace(url); + } + }; + } else { + window.location.replace(url); + } + } + n.initializeQfqClearMe(); n.initializeDatetimepicker(); + n.initializeIgnoreHistoryBtn(); n.Helper.calendar(); FilePond.registerPlugin(FilePondPluginFileValidateSize);