Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
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
document.addEventListener('click', function(e) {
// Check if the clicked element is a link to the Special:Search
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')) {
searchLink.addEventListener('click', function(e) {
e.preventDefault(); // Prevent the link from navigating
var searchInput = document.querySelector('#searchInput, #mw-searchInput'); // Adjust the selector as needed
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(); // Focus on the search input
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
            }
        });
    }
});
Cookies help us deliver our services. By using our services, you agree to our use of cookies.