Introduction:
"QueryHighlighter" is an open-source GitHub project designed to highlight search results in HTML documents. It uses CSS and JavaScript, making it incredibly simple and easy to use.
Key Features:
- Supports multiple search engines, including Google, Bing, Yahoo, DuckDuckGo, and more.
- Supports various search syntax, including wildcards, regular expressions, and more.
- Allows customization of highlighting styles.
How to Use:
Integrating "QueryHighlighter" into your HTML document is straightforward. Simply add the following code:
<script src="https://unpkg.com/queryhighlighter/dist/queryhighlighter.min.js"></script>
<script>
new QueryHighlighter("#my-search-results", {
// Search engine
searchEngine: "google",
// Search query
searchQuery: "queryhighlighter",
// Highlighting style
highlightStyle: {
background: "#ff0000",
color: "#ffffff",
fontWeight: "bold",
},
});
</script>
Please use this code with caution. [Learn more](link to additional details)
Code Example:
Here's an example of how to use "QueryHighlighter" to highlight search results:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>QueryHighlighter Example</title>
</head>
<body>
<h1>QueryHighlighter Example</h1>
<p>This is an example of using QueryHighlighter to highlight search results.</p>
<p>
<input type="text" id="my-search-results" placeholder="Search">
</p>
<script src="https://unpkg.com/queryhighlighter/dist/queryhighlighter.min.js"></script>
<script>
new QueryHighlighter("#my-search-results", {
// Search engine
searchEngine: "google",
// Search query
searchQuery: "queryhighlighter",
// Highlighting style
highlightStyle: {
background: "#ff0000",
color: "#ffffff",
fontWeight: "bold",
},
});
</script>
</body>
</html>
Please use this code with caution. [Learn more](link to additional details)
After running this example, when you input "queryhighlighter" into the search box and click the search button, you will see the search results highlighted.
"QueryHighlighter" also supports customization of highlighting styles. You can modify the highlightStyle
property to set the background color, text color, font weight, and more.
Here are some example code snippets:
// Set background color to yellow, text color to black, and font weight to normal
new QueryHighlighter("#my-search-results", {
highlightStyle: {
background: "#ffff00",
color: "#000000",
fontWeight: "normal",
},
});
// Set background color to red, text color to white, and font weight to bold
new QueryHighlighter("#my-search-results", {
highlightStyle: {
background: "#ff0000",
color: "#ffffff",
fontWeight: "bold",
},
});
Please use this code with caution. [Learn more](link to additional details)
Conclusion:
"QueryHighlighter" is an incredibly simple and user-friendly tool for highlighting search results in HTML documents. It helps you quickly highlight search results, making it a valuable asset for web developers.