ورود

View Full Version : جستجو در صفحه



hesam_hma
چهارشنبه 24 مرداد 1386, 15:03 عصر
سلام دوستان می خواستم بدونم چه جوری میشه درون یه صفحه امکان جستجویی قرار داد

که بشه متن ها ، لینک ها و... رو که در همان صفحه قرار داره رو پیدا کرد؟

shahab_ksh
چهارشنبه 24 مرداد 1386, 16:53 عصر
از JavaScript استفاده کنید

ClaimAlireza
پنج شنبه 25 مرداد 1386, 08:13 صبح
از JavaScript استفاده کنید


میشه یه مثال بزنید ...

ترجیحا کد java.

bigcowboy
شنبه 27 مرداد 1386, 17:18 عصر
میشه یه مثال بزنید ...

ترجیحا کد java.


<script
language="JavaScript" type="Text/Javascript"><!--
// Hide script from older browsers
var urlAddress = "http://www.hypergurl.com/searchpage.html";
var pageName = "Search page javascript";
function addToFavorites()
{
if (window.external)
{
window.external.AddFavorite(urlAddress,pageName)
}
else
{
alert("Sorry! Your browser doesn't support this function.");
}
}
// --></script>
<script language="JavaScript">
<!-- More javascripts http://www.hypergurl.com -->
var NS4 = (document.layers); // Which browser?
var IE4 = (document.all);
var win = window; // window to search.
var n = 0;
function findInPage(str) {
var txt, i, found;
if (str == "")
return false;
// Find next occurance of the given string on the page, wrap around to the
// start of the page if necessary.
if (NS4) {
// Look for match starting at the current point. If not found, rewind
// back to the first match.
if (!win.find(str))
while(win.find(str, false, true))
n++;
else
n++;
// If not found in either direction, give message.
if (n == 0)
alert("Not found.");
}
if (IE4) {
txt = win.document.body.createTextRange();
// Find the nth match from the top of the page.
for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
txt.moveStart("character", 1);
txt.moveEnd("textedit");
}
// If found, mark it and scroll it into view.
if (found) {
txt.moveStart("character", -1);
txt.findText(str);
txt.select();
txt.scrollIntoView();
n++;
}
// Otherwise, start over at the top of the page and find first match.
else {
if (n > 0) {
n = 0;
findInPage(str);
}
// Not found anywhere, give message.
else
alert("عبارت مورد نظر پیدا نشد");
}
}
return false;
}
</script>
<form
name="search" id="search" onsubmit="return findInPage(this.string.value);">
<div align="center">
<p><font size="3">
<input style="font-family:tahoma" name="string"
type="text" size="15" onchange="n = 0;" />
</font>
<input style="font-family:tahoma" name="submit"
type="submit" value="جستجو" />
</p>
</div>
</form>