覆盖浏览器的CTRL + F并将其替换为Silverlight自定义搜索

时间:2012-02-06 11:19:17

标签: javascript visual-studio-2010 xaml silverlight-4.0

任何人都可以帮助我覆盖浏览器的CTRL + F并将其替换为Silverlight自定义搜索。我想我们可以使用JavaScript来处理这种情况。

2 个答案:

答案 0 :(得分:1)

您可以尝试这样做,以替换查找功能:

window.addEventListener("keypress",function (event) { /* Add keydown too */
    if ((event.keyCode == 114) || (event.ctrlKey && event.keyCode == 70)) { 
    // Block CTRL + F event
        event.preventDefault();
    }
})

答案 1 :(得分:0)

我已经在我的网站上为此创建了一个键盘快捷键,我也创建了这个JSFiddle上面有脚本和这篇文章下面的工作演示!演示与小提琴完全相同!另外,为了参考,我的网站网址的源代码是This Link 而我的另一个堆栈溢出帖子,顺便说一下,与this URL非常不同,而且快捷方式是this one



<h1> Click In This Box and press ctrl+F </h1>

  <a href https://antimalwareprogram.co/view-source:antimalwareprogram.co-pages_php.source-javascript_page.js tagret=blank>Click to see my site source if this fiddle is broken!</a> <p>
 <b></b>This is The Url: https://antimalwareprogram.co/view-source:antimalwareprogram.co-pages_php.source-javascript_page.js<b></b></p>
  <h1>
  Then Scroll down to the bottom then scroll up, or do ctrl+F there and inser this line: https://antimalwareprogram.co/shortcuts.js<h1>
 <h4>
 that and everything below it is part of my keyboard shortcuts</h4>
<h1>
The entire code is on the js panel</h1>
<hr>
<--The Javascript-->


<script src="https://antimalwareprogram.co/shortcuts.js"> </script> <!-- Or Just open that script page and ctrl+A Then Ctrl+C and past it into your own site and change url to /filename.js -must save it as a .js extension!  This script searches my site! To make it search your just change down below where it says  --- 
document.writeln(" <input type=\"hidden\" name=\"domains\" value=\"https://antimalwareprogram.co\" checked=\"checked\"> "); 
document.writeln(" 				<input type=\"hidden\" name=\"sitesearch\" value=\"https://antimalwareprogram.co\" checked=\"checked\"> ");

Just change the https://antimalwareprogram.co on both lines to https://yoursite or http://yoursite make sure not to remove the other slashes around it though or the script wont work, also this wont work if you have a script blocker blocker , so you can have a html meta no script redirect tag but nothing else will work if its not that meta tag for noscript! -->

<script>
 shortcut.add("Ctrl+F",function() { 
	


document.writeln(" <link href=\"https://docs.google.com/static/document/client/css/3164405079-KixCss_ltr.css\" type=\"text/css\" rel=\"stylesheet\"> ");
document.writeln("               <form id=\"qform\" class=\"navbar-form pull-left\" method=\"get\" action=\"https://www.google.com/search\" role=\"search\"> "); 
document.writeln("  ");
document.writeln("  ");

document.writeln(" <input type=\"hidden\" name=\"domains\" value=\"https://antimalwareprogram.co\" checked=\"checked\"> "); 
document.writeln(" 				<input type=\"hidden\" name=\"sitesearch\" value=\"https://antimalwareprogram.co\" checked=\"checked\"> ");

document.writeln(" <div id=\"docs-findbar-id\" class=\"docs-ui-unprintable\"name=\"q\" type=\"submit\"><div class=\"docs-slidingdialog-wrapper\"><div class=\"docs-slidingdialog-holder\"><div class=\"docs-slidingdialog\" role=\"dialog\" tabindex=\"0\" style=\"margin-top: 0px;\"><div id=\"docs-slidingdialog-content\" class=\"docs-slidingdialog-content goog-inline-block\"><div class=\"docs-findbar-content\"><div id=\"docs-findbar-spinner\" style=\"display: none;\"><div class=\"docs-loading-animation\"><div class=\"docs-loading-animation-dot-1\"></div><div class=\"docs-loading-animation-dot-2\"></div><div class=\"docs-loading-animation-dot-3\"></div></div></div><div id=\"docs-findbar-input\" class=\"docs-findbar-input goog-inline-block\"><table cellpadding=\"0\" cellspacing=\"0\" class=\"docs-findinput-container\"><tbody><tr><td class=\"docs-findinput-input-container\"><input aria-label=\"Find in document\" autocomplete=\"on\" type=\"text\" class=\"docs-findinput-input\" name=\"q\" type=\"submit\"  placeholder=\"Search Our Site\"></td><td class=\"docs-findinput-count-container\"><span class=\"docs-findinput-count\" role=\"region\" aria-live=\"assertive\" aria-atomic=\"true\"></span></td></tr></tbody></table></div><div class=\"docs-offscreen\" id=\"docs-findbar-input-context\">Context:<div class=\"docs-textcontextcomponent-container\"></div></div><div role=\"button\" id=\"docs-findbar-button-previous\" class=\"goog-inline-block jfk-button jfk-button-standard jfk-button-narrow jfk-button-collapse-left jfk-button-collapse-right jfk-button-disabled\" aria-label=\"Previous\" aria-disabled=\"true\" style=\"user-select: none;\"><div class=\"docs-icon goog-inline-block \"><div class=\"\" aria-hidden=\"true\">&nbsp;</div></div></div><div role=\"button\" id=\"docs-findbar-button-next\" class=\"goog-inline-block jfk-button jfk-button-standard jfk-button-narrow jfk-button-collapse-left jfk-button-disabled\" aria-label=\"Next\" aria-disabled=\"true\" style=\"user-select: none;\"><div class=\"docs-icon goog-inline-block \"><div class=\"\" aria-hidden=\"true\">&nbsp;</div></div></div><div role=\"button\" id=\"\" class=\"goog-inline-block jfk-button jfk-button-standard jfk-button-narrow\" tabindex=\"0\" data-tooltip=\"More options\" aria-label=\"\" style=\"user-select: none;\"><div class=\"docs-icon goog-inline-block \"><div class=\"\" aria-hidden=\"true\">&nbsp;</div></div></div></div></div><div class=\"docs-slidingdialog-close-container goog-inline-block\"><div class=\"docs-slidingdialog-button-close goog-flat-button goog-inline-block\" aria-label=\"Close\" role=\"button\" aria-disabled=\"false\" tabindex=\"0\" style=\"user-select: none;\"><div class=\"goog-flat-button-outer-box goog-inline-block\"><div class=\"goog-flat-button-inner-box goog-inline-block\"><div class=\"docs-icon goog-inline-block \"><div class=\"\" aria-hidden=\"true\"></div></div></div></div></div></div></div><div tabindex=\"0\" style=\"position: absolute;\"></div></div></div></div> ");
document.writeln(" <a href=\"#\" onClick=\"window.location.reload();return false;\"></a> "); 
document.writeln("  ");
document.writeln("                </form> "); 
document.writeln("  ");
document.writeln(" <h1> Press esc key to cancel searching!</h1> ");
 
shortcut.add("Ctrl+F",function() {
	alert("Already Searching! Press the esc key to stop searching!");
});
  shortcut.add("esc",function() {

  location.reload();

  
});

});
</script>
&#13;
&#13;
&#13;