Creating a search functionality for your entire Weebly website requires server-side capabilities or integration with an indexing service like Google Custom Search Engine. However, I can provide you with a simple search functionality using only HTML, CSS, and JavaScript. Note that this will only work for searching within the content of the pages you include in the script and not scan your entire website.
You can add the following code to an embed code element in your Weebly site. Keep in mind to update the pages object with the actual content of your pages.
<!DOCTYPE html>
<html>
<head>
<style>
.search-container {
display: flex;
justify-content: center;
margin-bottom: 1rem;
}
.search-input {
width: 50%;
padding: .5rem;
}
.search-button {
background-color: #4CAF50;
border: none;
color: white;
cursor: pointer;
padding: .5rem 1rem;
}
.table-container {
display: flex;
justify-content: center;
}
table {
border-collapse: collapse;
width: 50%;
}
th, td {
border: 1px solid #ddd;
padding: .5rem;
text-align: left;
}
th {
background-color: #f2f2f2;
font-weight: bold;
}
</style>
</head>
<body>
<div class="search-container">
<input type="text" id="search-input" class="search-input" placeholder="Search term...">
<button onclick="search()" class="search-button">Search</button>
</div>
<div id="table-container" class="table-container"></div>
<script>
// You need to manually define your pages and their content here. This is just an example.
const pages = [
{
title: 'Home',
img: 'img_path/home_image.jpg',
content: 'Here is the content of the home page.'
},
{
title: 'About',
img: 'img_path/about_image.jpg',
content: 'Here is the content of the about page.'
},
// Continue adding your pages
];
function search() {
const searchTerm = document.getElementById('search-input').value;
const results = pages.filter(page =>
page.content.toLowerCase().includes(searchTerm.toLowerCase())
);
let output = `
<table>
<tr>
<th>Search term</th>
<th>Corresponding image</th>
</tr>
`;
results.forEach(result => {
output += `
<tr>
<td>${result.title}</td>
<td><img src="${result.img}" alt="${result.title}" /></td>
</tr>
`;
});
output += '</table>';
document.getElementById('table-container').innerHTML = output;
}
</script>
</body>
</html>
Please note that this code is only a basic and manual approach to search within your specific pages content. A more advanced search functionality would require setting up proper indexing and searching algorithms or using third-party services.