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

问题描述 投票:0回答:3

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

javascript visual-studio-2010 xaml silverlight-4.0
3个回答
2
投票

您可以尝试这个,来替换查找功能:

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

0
投票

我在我的网站上为此创建了一个键盘快捷键,我还创建了这个JSFiddle,其中包含脚本以及本文下面的工作演示!该演示与小提琴中的完全相同!另外,作为参考,我的网站网址的来源(如代码片段中所示)是此链接 顺便说一句,我的另一篇堆栈溢出文章与这篇文章非常不同,是 this URL 而 Shortcut.js 小提琴是 this

<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>


0
投票

对兰迪尔的回答做一点补充 (抱歉我无法添加评论) 如果 keypress 不适合您,您可以尝试使用事件 keydown 而不是 keypress。 它对我有用。

© www.soinside.com 2019 - 2024. All rights reserved.