Answered by:
Open programmatically search bar Win8 HTML5 JS

Question
-
Hi,
can anyone help me? I want to open programmatically (click on a button) the search sidebar in my Windows8 HTML/JS App.
Thanks in advance,
Daniel
Thursday, August 9, 2012 3:41 PM
Answers
-
Yes you can. See Windows.ApplicationModel.Search.SearchPane.show, as doc'd here: http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.search.searchpane.show.aspx
- Marked as answer by Jeff SandersMicrosoft employee, Moderator Thursday, August 9, 2012 7:21 PM
Thursday, August 9, 2012 7:20 PM
All replies
-
Hi Daniel,
No, you cannot do that. Search is a system command always initiated by the user.
-Jeff
Jeff Sanders (MSFT)
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Thursday, August 9, 2012 5:18 PM
Thursday, August 9, 2012 5:18 PMModerator -
Yes you can. See Windows.ApplicationModel.Search.SearchPane.show, as doc'd here: http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.search.searchpane.show.aspx
- Marked as answer by Jeff SandersMicrosoft employee, Moderator Thursday, August 9, 2012 7:21 PM
Thursday, August 9, 2012 7:20 PM -
Thanks Kraig!
Jeff Sanders (MSFT)
Thursday, August 9, 2012 7:21 PMModerator -
cool, thx kraig! ;)Thursday, August 9, 2012 8:45 PM
-
I have even mimic'ed the start menus "instant search" where you can just start to type (or ctrl+v) text and it will open the search pane.
showSearchCharm = function(text) { return Windows.ApplicationModel.Search.SearchPane.getForCurrentView().show(text); }; app.onactivated = function(event) { var _this = this; WinJS.UI.processAll().then(function() { return handleActivation(event); }); return document.body.addEventListener('keypress', function(event) { var clipboard, searchPane, _ref; if ((_ref = document.activeElement.tagName.toLowerCase()) === 'input' || _ref === 'select') { return; } if (event.ctrlKey && event.key === "v") { clipboard = Clipboard.getContent(); if (!clipboard.contains(StandardDataFormats.text)) { return; } clipboard.getTextAsync().done(function(text) { return showSearchCharm(text); }); event.preventDefault(); event.stopImmediatePropagation(); return false; } else { if (event.ctrlKey || event.key.length > 1) { return; } } showSearchCharm(event.key); event.preventDefault(); event.stopImmediatePropagation(); return true; }); };
Enjoy!
Monday, August 13, 2012 1:14 PM -
Thanks for the code. Just so you know, the RTM release of Win8 will have a show-on-keyboard-input feature for the Search Pane, so all of this will become much simpler.Monday, August 13, 2012 2:42 PM
-
Can't wait for it :) Hopefully it will also fix the "first click does nothing" problem of current selection controls.Tuesday, August 14, 2012 4:08 PM