[js] + wyszukiwarka

0

witam,
sprawa wygląda, prosiłbym o pomoc kogoś obeznanego dobrze w js, ponieważ potrzeuje skryptu, który po wpisaniu do formularz imienia i nazwiska, znajdzie je i wyświetli, problem polega na tym, że tych danych jest strasznie dużo jakieś 5000 i one są wypisane w pliku html, po wpisaniu powinno się ono pokazać tak jakt to jest z #kotwicami, jak to najlepiej i najekonomiczniej zrobić?
pzdr

0

chodzi ci o cos podobnego do szukania (Ctrl+F) ??
Jesli tak to wykozystaj wlasnie ten kod :D
Jesli nie, to prosilbym o dokladniejsze stwierdzenie.

PS: Jak nie masz dostepu do kodu przegladarki do szukania, to moge wkleic :D

0

chodzi mi o to, że mam np. dokument html, z imieniem i nazwiskiem w osobnej linijce, i na samej górze byłoby pole formularza do wpisania szukanych danych i skrypt po naciśnięciu guźnika przechodziłby do danego nazwiska na stronie, przy czym reszta byłaby cały czas widoczna na stronie
pzdr

0

No czyli tak jak szukanie w IE, tylko zeby nie robil obj.select()

Ponizej wklejam kod z IE (nie przerabialem go, zostawiam to Tobie :D moze przyda ci sie w czyms jeszcze :D)

plik findinc.dlg:

//<SCRIPT LANGUAGE="JavaScript"> 
function callHelp(elm)
{
if (null != elm.helpid)
{
window.showHelp(elm.helpfile, "" + parseInt(elm.helpid),
"popup");
}
else
{
if ("BODY" != elm.tagName)
{
callHelp(elm.parentElement);
}
}
}
function btnCancelClick()
{
window.close();
}
function getTextRange(elm)
{
var r = elm.parentTextEdit.createTextRange();
r.moveToElementText(elm);
return r;
}
function mouseClick()
{
if (window.event.srcElement.id.substring(0,3)
== "txt")
{
return;
}
if (window.event.button == 2)
{
callHelp(window.event.srcElement);
}
}
function txtDefaultESC()
{
if (event.keyCode == 27)
{
window.close();
return;
}
}
window.onerror = HandleError
var L_Dialog_ErrorMessage = "W tym oknie dialogowym wystąpił błąd.";
var L_ErrorNumber_Text = "Błąd: ";
function HandleError(message, url, line)
{
var str = L_Dialog_ErrorMessage + "\n\n"
+ L_ErrorNumber_Text + line + "\n"
+ message;
alert (str);
window.close();
return true;
}
function setFindState(fEvent) { if (fEvent && (event.propertyName != "value")) { return; } if (("" == txtFindText.value) == g_fFindEnabled) { btnFind.disabled = g_fFindEnabled; g_fFindEnabled = !g_fFindEnabled; } } var g_fFindEnabled = false;
var g_docLastFound;
var g_fFrameset = false;
var g_arrFrames = new Array();
var g_fSearchTopFrame = false;
var g_fFollowIframes = true;
var g_fError = false;
var g_docSearch ;
var g_rngWorking;
var g_rngFoundText;
var g_fFoundText = false;
var g_intDirection;
function FindHandleError(message, url, line)
{
var L_Find_DIALOG_NoAction_ErrorMessage = "Obiekt nie obsługuje tej akcji";
var L_Find_DIALOG_NoProperty_ErrorMessage = "Obiekt nie obsługuje tej właściwości lub metody";
if (message != L_Find_DIALOG_NoProperty_ErrorMessage)
{
if (message != L_Find_DIALOG_NoAction_ErrorMessage)
{
var str = L_Dialog_ErrorMessage + "\n\n"
+ L_ErrorNumber_Text + line + "\n"
+ message;
alert (str);
window.close();
}
else
{
g_fError = true;
g_fFrameset = false;
}
}
return true;
}
function CrawlPath()
{
var win = window.dialogArguments.unsecuredWindowOfDocument;
var i = 0;
if (g_fSearchTopFrame)
{
return win;
}
while (g_arrFrames[i] >= 0)
{
win = win.frames[g_arrFrames[i]];
i++;
}
return win;
}
function AtFrameset()
{
var win = CrawlPath();
return win.frames.length;
}
function AtIframe()
{
var win = CrawlPath();
return win.document.all.tags("IFRAME").length;
}
function IsLegalPage(win)
{
var arrBadFileTypes = new Array(".doc", ".xls", ".pdf");
var strHref = win.location.href;
for (i=0; i < arrBadFileTypes.length; i++)
{
if (strHref.lastIndexOf(arrBadFileTypes[i]) == (strHref.length - 4))
{
return false;
}
}
return true;
}
function GetCurrentPos()
{
var i = GetCurrentDepth();
return g_arrFrames[i];
}
function GetCurrentDepth()
{
var i = 0;
while (g_arrFrames[i] >= 0)
{
i++;
}
return i-1;
}
function MovePossible(fForward)
{
var intCurPos = GetCurrentPos();
var win = CrawlPath();
var winParent = win.parent;
if (fForward)
{
if ((winParent.frames.length - intCurPos - 1)
&& (IsLegalPage(winParent.frames[intCurPos + 1])))
{
return true;
}
else
{
return false;
}
}
else
{
return (intCurPos != 0);
}
}
function MoveUpFrameset()
{
var i = GetCurrentDepth();
g_arrFrames[i] = -1;
}
function MoveDownFrameset(fForward)
{
var i = GetCurrentDepth();
var win = CrawlPath();
g_arrFrames[i+1] = fForward ? 0 : win.frames.length - 1;
g_arrFrames[i+2] = -1;
}
function MoveWin(fForward)
{
var intDepth = GetCurrentDepth();
var intPos = GetCurrentPos();
g_arrFrames[intDepth] = fForward ? ++intPos : --intPos;
}
function MoveDoc(fForward)
{
if (g_fSearchTopFrame)
{
if (fForward)
{
g_fSearchTopFrame = false;
return true;
}
else
{
return false;
}
}
if (!fForward && (g_arrFrames[0] == 0) && (g_arrFrames[1] < 0)
&& window.dialogArguments.document.all.tags("IFRAME").length)
{
g_fSearchTopFrame = true;
return true;
}
if (g_fFollowIframes && AtIframe())
{
MoveDownFrameset(fForward);
while (!AtIframe() && AtFrameset())
{
MoveDownFrameset(fForward);
return true;
}
return false;
}
if (MovePossible(fForward))
{
MoveWin(fForward);
g_fFollowIframes = true;
while (!AtIframe() && AtFrameset())
{
MoveDownFrameset(fForward);
}
return true;
}
else
{
if (GetCurrentDepth() > 0)
{
MoveUpFrameset();
while (AtIframe() && !MovePossible(fForward)
&& (GetCurrentDepth() >= 0))
{
MoveUpFrameset();
}
if (AtIframe() && MovePossible(fForward))
{
g_fFollowIframes = false;
}
return MoveDoc(fForward);
}
}
return false;
}
function GetFirstDoc()
{
var win;
var doc = window.dialogArguments.document;
if (doc.all.tags("IFRAME").length)
{
g_fSearchTopFrame = true;
return doc;
}
while (!AtIframe() && AtFrameset())
{
MoveDownFrameset(true);
}
win = CrawlPath();
return win.document;
}
function setInitSearchRng()
{
findStartPoint();
if (g_fFrameset)
{
var win;
if (!AtIframe() && AtFrameset())
{
MoveDownFrameset(!radDirection[0].checked);
while (!AtIframe() && AtFrameset())
{
MoveDownFrameset(!radDirection[0].checked);
}
}
win = CrawlPath();
g_docSearch = win.document;
}
else
{
g_docSearch = window.dialogArguments.document;
}
if (g_docSearch .queryCommandState("BrowseMode")
&& g_docSearch .selection.type != "Text")
{
if (g_docSearch .body == null)
return;
g_rngWorking = g_docSearch .body.createTextRange();
}
else
{
g_rngWorking = g_docSearch .selection.createRange();
}
}
function directionAdjust()
{
g_fFoundText = (g_docSearch .selection.type == "Text");
if (radDirection[0].checked)
{
if (g_fFoundText)
{
g_rngWorking.moveEnd("character" , -1);
}
while (0 != g_rngWorking.moveStart("textedit", -10000))
{
}
g_intDirection = -1000000000;
}
else
{
if (g_fFoundText)
{
g_rngWorking.moveStart("character", 1);
}
while (0 != g_rngWorking.moveEnd("textedit", 10000))
{
}
g_intDirection = 1000000000;
}
}
function btnFindClick()
{
var fDone = false;
var L_FinishedDocument_Text = "Zakończono przeszukiwanie dokumentu.";
var index;
setInitSearchRng();
directionAdjust();
g_rngFoundText = g_rngWorking.duplicate();
success = g_rngFoundText.findText(txtFindText.value,
g_intDirection,
findFlags());
while ((!fDone) && success)
{
fDone = true;
try
{
g_rngFoundText.select();
}
catch (exception)
{
if (g_intDirection == 1000000000)
{
g_rngFoundText.moveStart("character" , 1);
while (0 != g_rngFoundText.moveEnd("textedit", 10000))
{
}
}
else
{
g_rngFoundText.moveEnd("character" , -1);
while (0 != g_rngFoundText.moveStart("textedit", -10000))
{
}
}
fDone = false;
success = g_rngFoundText.findText(txtFindText.value,
g_intDirection,
findFlags());
}
}
if (!success)
{
if (g_fFrameset)
{
if (MoveDoc(!radDirection[0].checked))
{
btnFindClick();
return;
}
}
alert(L_FinishedDocument_Text);
txtFindText.focus();
}
else
{
if (g_fFrameset)
{
g_docLastFound.execCommand("Unselect", false);
g_docLastFound = g_docSearch ;
}
g_rngFoundText.select();
g_rngFoundText.scrollIntoView(true);
}
}
function btnCancelClick2()
{
window.dialogArguments.findText = txtFindText.value;
window.close();
}
//</SCRIPT> 

Plik find.dlg (to glowne okienko dialogowe):

<HTML id=dlgFind STYLE="font-family: MS Shell Dlg; font-size: 8pt;
width: 39em; height: 13.2em">
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
<META HTTP-EQUIV="MSThemeCompatible" CONTENT="Yes">
<TITLE id=dialogTitle>
Znajdowanie
</TITLE>
<SCRIPT LANGUAGE="JavaScript" defer src="findinc.dlg">
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript" defer>
function findFlags()
{
var htmlMatchWord = 2;
var htmlMatchCase = 4;
var htmlMatchDiacritic = 536870912;
var htmlMatchKashida = 1073741824;
var htmlMatchAlefHamza = 2147483648;
return (htmlMatchWord * document.all.chkWholeWord.checked)
| (htmlMatchCase * document.all.chkMatchCase.checked)
| htmlMatchDiacritic | htmlMatchKashida | htmlMatchAlefHamza;
}
function loadBdy()
{
btnFind.onclick = new
Function("btnFindClick()");
btnFind.ondblclick = new
Function("btnFindClick()");
btnCancel.onclick = new Function("btnCancelClick2()");
document.onhelp = new Function("callHelp(window.event.srcElement)");
document.onmouseup = new Function("mouseClick()");
txtFindText.onpropertychange = new Function("setFindState(true)");
txtFindText.onfocus = new Function("txtFindText.select()");
txtFindText.onkeypress = new Function("txtDefaultESC()");
g_fFindStartPoint = true;
if ("" != window.dialogArguments.findText)
{
txtFindText.value = window.dialogArguments.findText;
}
txtFindText.focus();
txtFindText.select();
}
function findStartPoint()
{
if (g_fFindStartPoint)
{
g_fFindStartPoint = false;
var win = window.dialogArguments.unsecuredWindowOfDocument;
var doc = window.dialogArguments.document;
if (!g_fError && win.frames.length)
{
var win2;
g_fFrameset = true;
g_arrFrames[0] = 0;
g_arrFrames[1] = -1;
win2 = CrawlPath();
window.onerror = FindHandleError;
doc2 = win2.document;
window.onerror = HandleError;
while (doc2.selection.type == "None")
{
if (MoveDoc(true))
{
win2 = CrawlPath();
doc2 = win2.document;
}
else
{
g_arrFrames[0] = 0;
g_arrFrames[1] = -1;
break;
}
}
doc = GetFirstDoc();
g_docLastFound = doc;
}
if (doc.selection.type == "Control")
{
var r = doc.selection.createRange();
r = getTextRange(r(0));
r.select();
}
}
}
</SCRIPT>
</HEAD>
<BODY ID=bdy onload="loadBdy()" style="color: windowtext;
font-family: 'MS Shell Dlg';
font-size: 8pt; background: threedface; " topmargin=0 scroll=no>
<BUTTON id=btnFind ACCESSKEY=Z DISABLED=1 tabIndex=55 helpid=50026
helpfile="iexplore.hlp"
style="font-family: MS Shell Dlg; font-size: 8pt; position: absolute;
left: 27.78em; top: 1.0647em; width: 9em; height: 2.2em; " type=submit>
<U>Z</U>najdź następny
</BUTTON>
<DIV align=absMiddle id=divFindText
style="font-family: MS Shell Dlg; font-size: 8pt; position: absolute;
left: 0.98em; top: 1.2168em; width: 4.8em; height: 1.2168em; ">
<LABEL FOR=txtFindText ID=lblFindText tabIndex=-1 helpid=50027
helpfile="iexplore.hlp">
Z<U>n</U>ajdź:
</LABEL>
</DIV>
<INPUT type=text id=txtFindText ACCESSKEY=n tabIndex=15 helpid=50027
helpfile="iexplore.hlp"
style="font-family: MS Shell Dlg; font-size: 8pt; position: absolute;
left: 6.16em; top: 1.0647em; width: 20.36em; height: 2.1294em; ">
<BUTTON id=btnCancel tabIndex=60 helpid="0x6F1C" helpfile="windows.hlp"
style="font-family: MS Shell Dlg; font-size: 8pt; position: absolute;
left: 27.78em; top: 3.6504em; width: 9em; height: 2.2em; " type=reset>
Anuluj
</BUTTON>
<INPUT id=chkWholeWord ACCESSKEY=c type=checkbox tabIndex=25
helpfile="iexplore.hlp" helpid=50022
style="font-family: MS Shell Dlg; font-size: 8pt; position: absolute;
left: 1em; top: 4.2em; width: 1.2em; height: 1.2em;">
<INPUT ACCESSKEY=w type=checkbox tabIndex=35 helpid=50023
helpfile="iexplore.hlp"
id=chkMatchCase style="font-family: MS Shell Dlg; font-size: 8pt;
position: absolute; left: 1em; top: 6em; width: 1.2em; height: 1.2em;">
<DIV id=divWholeWord
style="font-family: MS Shell Dlg; font-size: 8pt; position: absolute;
left: 2.6em; top: 4.2588em; width: 13.46em; height: 1.521em; ">
<LABEL FOR=chkWholeWord ID=lblWholeWord tabIndex=-1 helpid=50022
helpfile="iexplore.hlp">
Uwzględnij tylko <U>c</U>ałe wyrazy
</LABEL>
</DIV>
<DIV id=divMatchCase style="font-family: MS Shell Dlg; font-size: 8pt;
position: absolute; left: 2.6em; top: 6.084em; width: 13.46em;
height: 1.521em; ">
<LABEL FOR=chkMatchCase ID=lblMatchCase tabIndex=-1 helpid=50023
helpfile="iexplore.hlp">
Uwzględnij <U>w</U>ielkość liter
</LABEL>
</DIV>
<FIELDSET id=fldDirection style="font-family: MS Shell Dlg; font-size: 8pt;
position: absolute; left: 16.7em; top: 3.5em; width: 9.7em;
height: 4.2em;">
<LEGEND id=lgdDirection>
Kierunek
</LEGEND>
</FIELDSET>
<INPUT id=radDirectionUp type=radio name=radDirection ACCESSKEY=G
tabIndex=42 helpid=50025 helpfile="iexplore.hlp"
style="font-family: MS Shell Dlg; font-size: 8pt; position: absolute;
left: 17.6em; top: 5.4em; width: 1.2em; height: 1.2em; ">
<DIV id=divDirectionUp style="font-family: MS Shell Dlg;
font-size: 8pt; position: absolute; left: 19.2em; top: 5.3235em;
width: 3.5em; height: 1.521em; ">
<LABEL ID=lblDirectionUp style="font-family: 'MS Shell Dlg'; font-size: 8pt"
FOR=radDirectionUp
helpid=50025
helpfile="iexplore.hlp"> <U>G</U>óra </LABEL>
</DIV>
<INPUT id=radDirectionDown type=radio CHECKED name=radDirection
ACCESSKEY=D tabIndex=47 helpid=50024 helpfile="iexplore.hlp"
style="font-family: MS Shell Dlg; font-size: 8pt; position: absolute;
left: 22.5em; top: 5.4em; width: 1.2em; height: 1.2em; ">
<DIV id=divDirectionDown style="font-family: MS Shell Dlg;
font-size: 8pt; position: absolute; left: 24.1em; top: 5.3em;
width: 4.9em; height: 1.521em; ">
<LABEL ID=lblDirectionDown style="font-family: 'MS Shell Dlg'; font-size: 8pt"
FOR=radDirectionDown helpid=50024 helpfile="iexplore.hlp">
<U>D</U>ół </LABEL>
</DIV>
</BODY>
</HTML>
0

heh dzięki, spróbuje coś z tym zrobić ale czy nie dałoby się tego zrobić łatwiej i tak by kod skryptu był w tym samym pliku co te dane, które będą przeszukiwane, ponieważ bardzo by mi to ułatwiło sprawe?
dzięki pzdr

0

Jak znasz sie na JS w skali od 1 do 10??

Kod dalo by sie skrocic:

  • nie potrzebujesz obslugi IFRAMEow
  • wywolywania Helpa
  • obslugi bledow (zakladamy ze kod strony jest poprawny :) )
  • zapamietywanie ostatnio znalezionego slowa
  • obslugi wielu jezykow (:D)

Jesli to wywalisz to zostanie niewiele i bez problemow bedzie mozna zaladowac to do tego samego pliku co dane.

Jesli nie lubisz kombinowac (lub nie znasz sie na tyle na JS) to moge przeslac gotowy kod, tylko:

  • wklej kawalek kodu HTML stronki (jako przyklad na ktorym bede operowal)
  • czekaj cierpliwie, bo napisze go jak bede mial troche czasu (tj. najpozniej jutro :P)
0

przyznam, że js znam bardzo słabo a niestety nie mogę wykorzystać php co by mi było o wiele łatwiej, jeśli miałbyś czas i chęci to bardzo bym prosił o gotowy kod, możliwie jak najprostszy i bez żadnych wodotrysków, tylko prosta szukarka, plik, który będzie przeszukiwany powstaje, gdyż na razie mam go w wordzie ale przerobie to na html i tam właśnie ten skrypt będzie mi bardzo potrzebny
dzięki pzdr

0

no to prosze bardzo, "troche" obcieta funkcyjka :D

<script language="JavaScript" type="text/javascript">
function Szukaj(text)
 {
 FoundText = document.body.createTextRange().duplicate();
  if (FoundText.findText(text, 1000000000, 2))
   window.scrollBy(0, FoundText.offsetTop);
 }
</script>
<input id="znajdz" type="text" value="text"> <input type="button" value="Szukaj" onclick="Szukaj(document.getElementById('znajdz').value);">

<br><br><br><p></p>
jakis TEXt<br><br><br><br><br><br><br>
znowu text<br><br><br><br><br><br><br>
teraz mamy Ala<br><br><br><br><br><br>
teraz Kasia<br><br><br><br><br><br><br>
a teraz alana<br><br><br><br><br><br>
i znow Kasia<br><br><br><br><br><br>
no i koniec

Oczywiscie to szuka "gdzie popadnie" czyli jak np napiszesz
w1: Ala - podwladna Kasia
w2: Kasia - przelozona Ala
I bedziesz szukal "Ala", to zatrzyma sie przy w1, ale jak bedziesz szukal "Kasia" to tez zatrzyma sie przy w1, bo znajduje pierwszy pasujacy wyraz
BTW: aby znaleŹĆ ostatni pasujacy piszesz nie 1000000000 lecz <font color="red">-</font>1000000000

Bo rozumiem ze nie chcialo by ci sie wypisywac przy kazdym wierszu (pozycji tej listy) dodatkowego znacznika, cos typu

0

Serdeczne dzięki desperat, dokładnie o coś takiego mi chodziło [browar]
uratowałeś mi życie, teraz mogę przejść dalej do pracy, jeszcze raz wielkie dzięki
pzdr


witam ponownie,
mam niestety problem z powyższym skryptem, jak się okazało funkcjonuje bez zarzutu pod IE na WinXP pro, ale gdy chce włączyć strone pod WinXP z Sp2 to niestety już nie działa, co robić?

0
mynio napisał(a)

funkcjonuje bez zarzutu pod IE na WinXP pro, ale gdy chce włączyć strone pod WinXP z Sp2 to niestety już nie działa, co robić?

Hmmm, dziwne. Bo ja mam tez XP SP2 i mi dziala dobrze. Moze masz jakies ograniczenia co do dzialania skryptow na stronie. SP2 dodaje rozne bezsensowne ograniczenia, ktore blokuja niektore dziory, ale uniemozliwiaja poprawne wyswietlanie niektorych stron.

0

ok dzięki, skoro mówisz, że u Ciebie działa to przyjże się temu bliżej, u siebie nie mam sp2 i dlatego wszystko było ok a dziś przy próbie odpalenia na sp2 nic z tego nie wyszło
pzdr

0

witam ponownie,
czy dałoby radę w miarę prosto przerobić ten skrypt by była opcja pokaż dalej lub coś takiego jeśli istniałyby takie same dane, coś w stylu przejdź dalej?
pzdr

1 użytkowników online, w tym zalogowanych: 0, gości: 1