More actions
Content deleted Content added
Created page with "→Any JavaScript here will be loaded for all users on every page load.: document.addEventListener('DOMContentLoaded', function() { document.addEventListener('click', function(e) { // Check if the clicked element is a link to the Special:Search if (e.target.tagName === 'A' && e.target.href.includes('Special:Search')) { e.preventDefault(); // Prevent the link from navigating var searchInput = document.querySelector('#searchInp..." |
No edit summary |
||
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ |
/* Any JavaScript here will be loaded for all users on every page load. */ |
||
document.addEventListener('DOMContentLoaded', function() { |
document.addEventListener('DOMContentLoaded', function() { |
||
// This assumes you've given your link an ID for easy targeting |
|||
⚫ | |||
// |
var searchLink = document.querySelector('a[href*="Special:Search"]'); // Finds the first link to Special:Search |
||
if (searchLink) { |
|||
if (e.target.tagName === 'A' && e.target.href.includes('Special:Search')) { |
|||
⚫ | |||
e.preventDefault(); // Prevent the link from navigating |
|||
e.preventDefault(); // Stops the link from causing a page load |
|||
var searchInput = document.querySelector('input[type="search"], #searchInput'); // Adjust based on your wiki's search input |
|||
if (searchInput) { |
if (searchInput) { |
||
searchInput.focus(); // |
searchInput.focus(); // Focuses the search input |
||
// Trigger any additional behaviors here if necessary |
|||
} |
} |
||
} |
}); |
||
} |
} |
||
}); |
}); |
Revision as of 22:21, 13 March 2024
/* Any JavaScript here will be loaded for all users on every page load. */
document.addEventListener('DOMContentLoaded', function() {
// This assumes you've given your link an ID for easy targeting
var searchLink = document.querySelector('a[href*="Special:Search"]'); // Finds the first link to Special:Search
if (searchLink) {
searchLink.addEventListener('click', function(e) {
e.preventDefault(); // Stops the link from causing a page load
var searchInput = document.querySelector('input[type="search"], #searchInput'); // Adjust based on your wiki's search input
if (searchInput) {
searchInput.focus(); // Focuses the search input
// Trigger any additional behaviors here if necessary
}
});
}
});