MediaWiki talk:Search-results-new-tab.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Note. This JS is no longer working right. It not only automatically opens the search results list in a new tab as it should. It also opens it in the same tab. So it is creating 2 search result pages. It shouldn't be doing that. --Timeshifter (talk) 14:06, 5 December 2013 (UTC)[reply]

Note: Here are the component parts and what they effect:

#searchform - embedded search form at top right of every page.
#searchbox - embedded archive search forms. For example; Template:Village pump archives.
#search, .search-types, #search-types - Special:Search.
#powersearch - advanced search at Special:Search. This is after one clicks the advanced search link at Special:Search to get the dropdown of search choices. Then when one clicks the search button #powersearch applies to it.
There is also a JS (JavaScript) import that uses Ctrl-click (PC) and Command-click (Mac) to open search result lists and suggestions in a new tab. See: MediaWiki talk:Gadget-search-new-tab.js

Problem with advanced search. Fixed[edit]

See this discussion about a problem with advanced search on Wikia, and the solution:

I see the same problem here on the Commons too. Also on Wikipedia:

Thanks for fixing the problem, Rd232! --Timeshifter (talk) 07:45, 31 March 2012 (UTC)[reply]
For the record, the addition of #powersearch fixed the problem. See diff of March 30, 2012 change. So searches with the advanced search button at Special:Search also open in new tabs. This is after one clicks the advanced search link to get the dropdown of search choices. Then when one clicks the search button the results open in a new tab. --Timeshifter (talk) 03:58, 25 July 2012 (UTC)[reply]

Can import into any-language Wikipedia[edit]

For those who are interested this works on Wikipedia too. Copy and paste Import the JavaScript (JS) directly into here:

The above links are for English Wikipedia. Change the links as necessary for other-language Wikipedias. Remember to copy import the JS directly from MediaWiki:Search-results-new-tab.js

Importing does not seem to work from the Commons to Wikipedia. --Timeshifter (talk) 08:32, 9 April 2012 (UTC)[reply]

Importing is different when it's not on the local site. I fixed it for you in this edit. Killiondude (talk) 20:17, 5 May 2012 (UTC)[reply]
The function importScriptURI was deprecated on MW 1.17 (the current version is 1.20wmf2). Please use mw.loader.load instead. Helder 20:29, 5 May 2012 (UTC)

Helder. This is working for me on Wikipedia at en:User:Timeshifter/common.js:

importScriptURI('//commons.wikimedia.org/w/index.php?title=MediaWiki:Search-results-new-tab.js&action=raw&ctype=text/javascript');

What exactly should I be using instead? --Timeshifter (talk) 20:44, 5 May 2012 (UTC)[reply]

Thanks to User:Killiondude for telling me what exactly to use! Here is what people can add to en:Special:MyPage/common.js:
/* Open search results list and search suggestions in new browser tab */
/* commons.wikimedia.org/wiki/MediaWiki_talk:Search-results-new-tab.js */
mw.loader.load('//commons.wikimedia.org/w/index.php?title=MediaWiki:Search-results-new-tab.js&action=raw&ctype=text/javascript');
mw.loader.load was substituted for importScriptURI
For more info: mw:RL/DM#mediaWiki.loader --Timeshifter (talk) 06:16, 8 May 2012 (UTC)[reply]

Discussions elsewhere for opening search result lists and suggestions in new tabs[edit]

I proposed a gadget (in preferences) for opening search results and suggestions in new tabs. See:

I suggested basing it on the JavaScript from here:

Bug[edit]

See here. Helder 14:03, 12 April 2012 (UTC)

I think that's a bug in Chrome. All the script does is put target: '_blank' on the relevant links; if Chrome opens a new tab in the way you described, that's Chrome's choice. At any rate, even if it's possible to accommodate Chrome by changing the script, I've not the faintest idea how. Rd232 (talk) 14:52, 12 April 2012 (UTC)[reply]
Oh well.. I've disabled it for now :-( Helder 12:54, 16 April 2012 (UTC)

MediaWiki gadget, preference, or default setting[edit]

I started this Bugzilla thread: "Bug 35974 - Preference or default setting to open search results and suggestions in new tab".

I also started a discussion here:
http://www.mediawiki.org/wiki/Gadget_kitchen/Requests --Timeshifter (talk) 23:54, 14 April 2012 (UTC)[reply]

Listed this search enhancement at Help:Searching[edit]

I linked to this page from Help:Searching. I also explained how to get this to work on Wikipedia at en:Help:Searching. --Timeshifter (talk) 11:10, 25 April 2012 (UTC)[reply]

Opening archive search result lists in new tabs[edit]

Try the archive search forms found on these pages:

They open in the same tab. --Timeshifter (talk) 20:11, 31 May 2012 (UTC)[reply]

A solution has been provided by User:Rd232. See User talk:Rd232#Archive searches do not open in new tabs. This works:
/* Open search result lists and suggestions in new browser tabs */

$(function () {
    $('#searchform, #search, #powersearch, #searchbox, .search-types, #search-types').attr({ target: '_blank' });
});
The only change to the JS is the addition of #searchbox. --Timeshifter (talk) 04:56, 2 July 2012 (UTC)[reply]
✓ Done Rd232 (talk) 07:05, 2 July 2012 (UTC)[reply]
Thanks! --Timeshifter (talk) 09:59, 3 July 2012 (UTC)[reply]