Admin Forum:Open search results in new tab. JS or CSS?

Is there a way to make search open in a new tab? I hate when it covers up my existing page, and I don't want to have to open up a throwaway page just to use search. This is such a poor design feature of the MediaWiki software.

Anyway, any ideas on how to fix this just for myself with JS or CSS? And what about for a whole wiki? For me personally, I use the Firefox browser. ---Timeshifter (talk) 02:32, March 9, 2012 (UTC)


 * You could use JS to add a target attribute:


 * See here for info about JS files.-- Pecoes 10:31, March 9, 2012 (UTC)


 * Thanks! Works great here:
 * http://community.wikia.com/wiki/User:Timeshifter/global.js


 * That JS and CSS cheat sheet is very helpful. ---Timeshifter (talk) 12:23, March 9, 2012 (UTC)


 * I noticed one problem though. When I search from Special:Search it does not open the search results in a new tab. Can this also be done? ---Timeshifter (talk) 15:20, March 9, 2012 (UTC)


 * That's a different form. This should do it:

-- Pecoes 16:54, March 9, 2012 (UTC)


 * Thanks. I put it here again:
 * http://community.wikia.com/wiki/User:Timeshifter/global.js
 * I substituted this JS code for the other code and it works on the Community Wiki, but only partially on my main wiki, the cannabis wiki. Results of Special:Search opens up in a new tab here, but not on the cannabis wiki:
 * http://cannabis.wikia.com/wiki/Special:Search ---Timeshifter (talk) 07:53, March 10, 2012 (UTC)


 * I just tested it and it worked fine. Were you logged in when you tested this? User:Timeshifter/global.js will work only for you and only as you're logged in. -- Pecoes 08:38, March 10, 2012 (UTC)


 * Yes, I am logged in. Search results open in a new tab here:
 * http://community.wikia.com/wiki/Special:Search
 * but not here:
 * http://cannabis.wikia.com/wiki/Special:Search


 * Maybe it has to do with the JS and CSS Cheatsheet info about the upcoming Special:Mypage/common.js changes? See:
 * http://cannabis.wikia.com/wiki/MediaWiki:Common.js
 * That is working on all skins (Wikia and Monobook) on the Cannabis Wiki. Is anything there interfering with your JS I added here?:
 * http://community.wikia.com/wiki/User:Timeshifter/global.js


 * Also, I am an admin on the cannabis wiki. Maybe that has something to do with it. I don't know. ---Timeshifter (talk) 09:19, March 10, 2012 (UTC)


 * The fact that you're an admin doesn't enter into it and the future functionality of Special:Mypage/common.js is irrelevant now. It should work. It does for me and I'm using the same code. Try to refresh and if that doesn't help purge. -- Pecoes 09:43, March 10, 2012 (UTC)


 * It is working now! Out of curiosity I tried it again without refreshing or purging first. I had already refreshed before. So maybe enough time elapsed since the last time I was here for the server to purge its cache.


 * I added it also to here just now, and did a hard refresh:
 * http://cannabis.wikia.com/wiki/MediaWiki:Common.js
 * I logged out, and search results from both forms open in a new tab. Is this OK to do for a wiki? Does Wikia mind? ---Timeshifter (talk) 13:09, March 10, 2012 (UTC)


 * I can't imagine why they would mind. The rule of thumb seems to be: As long as you obstruct neither ads nor content you can do whatever you like. This little change does neither. -- Pecoes 13:20, March 10, 2012 (UTC)


 * Tagging FAQ. -- Fandyllic (talk &middot; contr) 12 Mar 2012 12:57 PM Pacific

The changes made so far have been greatly useful to me so far. I do many more searches now with Wikia's search engine instead of Google site searches. I use the Firefox browser. Google does not provide a Google Toolbar for Firefox. So previously I was frequently using the Google site searches in the search menu in the Cannabis Wiki. But it was a 2-step process that required opening up a new search tab first. Now I can search immediately from Wikia's search.

There is another problem. When search finds something that matches the search term, then the page opens in the same tab. For example; when the search term comes up in the dropdown list of suggestions. Try searching for "Paris" to see what I mean. It happens when searching for many city names because many cities have pages, and because there are many redirects from the basic city names to the full city+state+nation article title. So if one clicks on an item in the dropdown list of search suggestions then it opens in the same tab.

Special:Search results on the Cannabis Wiki and on the Community Wiki no longer open in a new tab. Maybe all these problems are related. ---Timeshifter (talk) 08:55, March 15, 2012 (UTC)


 * I'm sorry but I can't reproduce your problem. I loaded the exact same code that you have in w:c:cannabis:MediaWiki:Common.js and the exact same code you have in w:User:Timeshifter/global.js and it all worked fine. Do you have code anywhere else? -- Pecoes 17:40, March 15, 2012 (UTC)


 * I am trying to figure it out. Created this as an aid:
 * http://cannabis.wikia.com/wiki/JS_and_CSS_cheatsheet
 * Will take more time, probably tomorrow. ---Timeshifter (talk) 19:12, March 15, 2012 (UTC)

I am wondering how much of this legacy CSS in Common.css is really necessary:
 * http://cannabis.wikia.com/index.php?title=MediaWiki:Common.css&oldid=6322

I am thinking of deleting all of the legacy CSS since it was ignored by Wikia.css unless one made a special effort to import it. See:
 * http://cannabis.wikia.com/index.php?title=MediaWiki:Common.css&action=history

I only want to keep the CSS I added since I know more about what it is for. ---Timeshifter (talk) 22:14, March 15, 2012 (UTC)


 * I looked over the CSS but I have no idea what most of is/was needed for. I'm not exactly an old hand, you know. My MediaWiki/Wikia knowledge is barely two months old...


 * How about the open-search-in-new-page script? Does that work now? I looked over all of your script files and I can't find anything that would conflict with it. The only suggestion I could make is to open your web browser's error console and keep an eye open for JavaScript errors. There's the remote possibility that something else doesn't work and prevents this snippet from working as well. That's all I can think of at any rate.


 * (My fancy new signature almost works now. Sorry for posting all that messy raw code in the other thread!) 11:32, March 17, 2012 (UTC)


 * I will need some time to remove all the old CSS code and see if the wiki works OK without it. In the meantime there is the same problem. Searches open in a new tab from all search forms except when one clicks on one of the suggestions from the dropdown menu. Maybe that is not considered a search, but is considered more in the way of just clicking a link. ---Timeshifter (talk) 15:40, March 17, 2012 (UTC)


 * I removed a bunch of old CSS here:
 * http://cannabis.wikia.com/wiki/MediaWiki:Common.css


 * I looked at all the CSS and JS pages listed here for stuff that could be deleted:
 * http://cannabis.wikia.com/wiki/JS_and_CSS_cheatsheet_links
 * Everything remaining is being used. I purged and refreshed yesterday.


 * I still have the same problem on Firefox when clicking search dropdown links that I mentioned in my last comment. Everything else is working fine, and search results open in a new tab. Only the search dropdown links open in the same tab.


 * I tested on Internet Explorer too. Same problem, plus an additional problem. Special:Search does not open in a new tab under any circumstances. I am logged in, too. ---Timeshifter (talk) 22:21, March 20, 2012 (UTC)


 * I can confirm that clicking on a link from that dropdown menu won't open the results in a new tab. That's because these suggestions are fetched via AJAX and there's no actual submit. The JavaScript routines bypass the HTML form.


 * Strangely enough the suggestions dropdown has stopped working altogether. It looks like Wikia staff is tinkering with it... --


 * The suggestions dropdown is working now for me. Nothing drops down of course if the search term is not found in the pages of the wiki that are searched. Not all pages are searched from the search form at the top right of pages.


 * On the Wikimedia Commons I pointed to this forum and suggested opening search results in a new tab. It has been implemented (via a JS import)! See:
 * commons:Commons:Requests for comment/improving search. ---Timeshifter (talk) 18:40, March 23, 2012 (UTC)

(unindent). Clicking on search suggestions (from the dropdown menu) is still not opening in a new tab in the cannabis wiki or community wiki.

It works on the Wikimedia Commons. See:
 * commons:Special:Search
 * commons:Commons:Requests for comment/improving search

JS on the Commons that fixes this problem:
 * commons:MediaWiki:Search-results-new-tab.js - will this work on Wikia?

JS importing instructions and code:
 * commons:MediaWiki talk:Search-results-new-tab.js

I like that this JS modification is imported on the Commons. That way it is automatically updated for all users who are using it. This is important if the overall MediaWiki software updates and changes effect search in ways that require updates in this JS modification. ---Timeshifter (talk) 15:48, March 25, 2012 (UTC)


 * So the solution they gave you at wikimedia.org doesn't work after all? I gotta say: I was a little surprised, when you told me it did. I took your word for it though. :)


 * I looked at the searchform at WikiMedia and has nothing in common with the one at Wikia. That one uses a plain HTML select and submits the form when you've picked a suggestion. This one does not use the select and it does not submit the form. Apples and oranges.


 * Poring over oasis_shared_js I found the instruction that opens the link. It is encapsulated in WikiaSearchApp.initSuggest. You might get away with overriding WikiaSearchApp.initSuggest:


 * I tested it and it seems to work. --