On Sharepoint Online I have created a code snippet and have this code in it:
<div align="center">
<input type="text" onKeyDown="if(event.keyCode==13) doSearch();" id="SearchQuery" size="100">
<br/><br/>
<button type="button" onclick="javascript:doSearch();">Search</button>
</div>
<script type="text/javascript">
function doSearch(){
var theSearchQuery = document.getElementById('SearchQuery');
var theURLToGoTo = "https://www.google.com/webhp?#q=" + theSearchQuery.value;
window.location= theURLToGoTo;
}
</script>
It works great when you type something in the search box and you click the button with the mouse pointer. As in, it opens the Google screen with the search from the text box in the right place. I.e. it does the Google Search. However, when you enter something in the textbox and press enter instead of running the script, it for some reason opens up the edit function of the Sharepoint page?
UPDATE The code works perfectly if on a blank HTML page. Is it because Sharepoint Online blocks the onKeyDown or something?