Jump to content

Ctrl + F


Recommended Posts

Siteme html yahut asp hiç farketmez bir dille ctrl + f gibi bir arama kısmı oluşturmak isiyorum. İnsanlar aradıklarında o safa üzerindeki yazıları sanki tarayısılarından ctrl + f tuşlarına basarak arıyorlarmış gibi görünmesini istiyorum. Yardımlarınız için şimdiden teşekkürler.
Link to comment
Share on other sites

php böyle birşeye dokunamaz zaten imkan veriyorsa tarayıcı ancak javascriptte olur javascript ile tuşları alabilrsn onunla olr php server taraflı olduğu içn kullanıcıyla o şekilde etkileşime giremez zatn webservr üzerinde dosya isteniln şekilde derlenerk html halinde kullanıcıya yollanır ancak js ile olur dediğin

asp de aynı mantık la işler ancak asp.net biraz farklı onda da javascript devreye giriyor ancak visual studio da sürükle bırak hazır fonksiyonlar vs kullanma imkanı var ya asp.net de bunları harmanlamışlar yani orada kısa yoldan yazdığın bir asp.net kodu js haline dönüşebilir basit bir şekilde temelde yine aynı mantık
yaptıkları şey javascripti içine sokuyorlar sen uğraşmıyorsun

Link to comment
Share on other sites

[quote name='mephex' date='31 Ocak 2011 - 00:19 ' timestamp='1296426551' post='954482']
php böyle birşeye dokunamaz zaten imkan veriyorsa tarayıcı ancak javascriptte olur javascript ile tuşları alabilrsn onunla olr php server taraflı olduğu içn kullanıcıyla o şekilde etkileşime giremez zatn webservr üzerinde dosya isteniln şekilde derlenerk html halinde kullanıcıya yollanır ancak js ile olur dediğin

asp de aynı mantık la işler ancak asp.net biraz farklı onda da javascript devreye giriyor ancak visual studio da sürükle bırak hazır fonksiyonlar vs kullanma imkanı var ya asp.net de bunları harmanlamışlar yani orada kısa yoldan yazdığın bir asp.net kodu js haline dönüşebilir basit bir şekilde temelde yine aynı mantık
yaptıkları şey javascripti içine sokuyorlar sen uğraşmıyorsun
[/quote]
İlginiz için çok teşekkürler ama kod olarak paylaşımda bulunabilirmisiniz?
Direk siteye ekleyeceğim bir biçimde

Link to comment
Share on other sites

[codebox]<font face="Tahoma" size="2"><b>Bulunulan sayfa içinde arama <script language="JavaScript">var NS4 = (document.layers); // hangi browser?var IE4 = (document.all);var win = window;var n = 0;function findInPage(str) {var txt, i, found;if (str == "e")return false;if (NS4) {if (!win.find(str))while(win.find(str, false, true))n++;elsen++;if (n == 0)alert("Aradığınız kelime sayfada bulunamadı.");}if (IE4) {txt = win.document.body.createTextRange();for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {txt.moveStart("character", 1);txt.moveEnd("textedit");}if (found) {txt.moveStart("character", -1);txt.findText(str);txt.select();txt.scrollIntoView();n++;}else {if (n > 0) {n = 0;findInPage(str);}elsealert("Aradığınız kelime sayfada bulunamadı.");}}return false;}</script></b></font><form name="search" onSubmit="return findInPage(this.string.value);"><font size=3><input name="string" type="text" size=15 onChange="n = 0;"></font><input type="submit" value=" Ara "></form>[/codebox]

BU kod var.... sadece internet explorer da çalışıyor...

Link to comment
Share on other sites

abi kod olarak php de imaknsız gibi :) çünkü browser buna izin vermeli ve sen js olarak yapmalısın yani zaten ctr+f olarak kullanamazsın çünkü o browser de tanımlı mesala shift+5 vs. gibi yapabilrsin kullanıcı bu tuşlara bastığında search dosyasına yönlenir aslında bu yönlendirme konusunda yaratıcı olunabilir ama aslıs mesele yani olursa ancak javascript ile olur

burada örnek bi kod var incelersen

[code]http://www.cigicigi.gen.tr/web-programlama/36241-javascript-sayfaya-kisayol-tusu-ekleme.html[/code]

burda da biraz döküman var

[code]http://hotfile.com/dl/100660781/fea13cb/java_script.rar.html[/code]

incele bunları bişiler çıkabilir ortaya... Kolay Gelsin ;)

Link to comment
Share on other sites

  • 2 hafta sonra ...

[codebox]<script type="text/javascript">
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Robin Winslow | http://www.robinwinslow.me.uk */
// Find and select all text in the document that matches the "value" of the element passed
// If no element if passed, it will attempt to use the value of "this"
// Only works in a browser that supports the "window.getSelection" method, as other selection methods don't support multiple selectionsz
function performMultiSearch(elem,searchElem) {
// set up variables
var searchString; // Will hold the text to search for
var theSelection; // Will hold the document's selection object
var textNodes; // Will hold all the text nodes in the document

// Set it to search the entire document if we haven't been given an element to search
if(!searchElem || typeof(searchElem) == 'undefined') searchElem = document.body;

// Get the string to search for
if(elem && elem.value) searchString = elem.value;
else if(this && this.value) searchString = this.value;

// Get all the text nodes in the document
textNodes = findTypeNodes(searchElem,3);

// Get the selection object
if(window.getSelection) theSelection = window.getSelection(); // firefox
else { // some other browser - doesn't support multiple selections at once
alert("sorry this searching method isn't supported by your browser");
return;
}

// Empty the selection
theSelection.removeAllRanges(); // We want to empty the selection regardless of whether we're selecting anything

if(searchString.length > 0) { // make sure the string isn't empty, or it'll crash.
// Search all text nodes
for(var i = 0; i < textNodes.length; i++) {
// Create a regular expression object to do the searching
var reSearch = new RegExp(searchString,'gmi'); // Set it to 'g' - global (finds all instances), 'm' - multiline (searches more than one line), 'i' - case insensitive
var stringToSearch = textNodes[i].textContent;
while(reSearch(stringToSearch)) { // While there are occurrences of the searchString
// Add the new selection range
var thisRange = document.createRange();
thisRange.setStart(textNodes[i],reSearch.lastIndex - searchString.length); // Start node and index of the selection range
thisRange.setEnd(textNodes[i],reSearch.lastIndex); // End node and index of the selection
theSelection.addRange(thisRange); // Add the node to the document's current selection
}
}
}

return;
}

// Will find and select the first instance of the value of the passed element, then when called again will moves on to the next instance
// If no element passed it will try to get the value from "this"
function performSingleSearch(elem,searchElem) {
// set up variables
var searchString; // Will hold the text to search for
var theSelection; // Will hold the document's selection object
var textNodes; // Will hold all the text nodes in the document

// Set it to search the entire document if we haven't been given an element to search
if(!searchElem || typeof(searchElem) == 'undefined') searchElem = document.body;

// Get the string to search for
if(elem && elem.value) searchString = elem.value;
else if(this && this.value) searchString = this.value;

if(searchString && searchString.length > 0) { // make sure the string isn't empty, or it'll crash.
if(window.getSelection) { // Firefox
// Get the selection
theSelection = window.getSelection();

// Get all the text nodes in the document
textNodes = findTypeNodes(searchElem,3);

// If there's already a selection, and it's the string we're searching for
var searchMatch = new RegExp(searchString,'i');
if(theSelection.rangeCount == 1 && searchMatch(theSelection.getRangeAt(0).toString())) {
var currentRange = theSelection.getRangeAt(0);
theSelection.removeAllRanges();
// Move on to the next occurrence of it by iterating through text nodes...:
for(var i = 0; i < textNodes.length; i++) {
// If this text node is before the currentRange, ignore it and carry on to the next one
if(currentRange.comparePoint(textNodes[i],0) == -1 && currentRange.startContainer != textNodes[i]) continue;
// If this text node is the same as the currentRange, find the point in the currentRange
else if((currentRange.comparePoint(textNodes[i],0) == -1 && currentRange.startContainer == textNodes[i]) || (currentRange.comparePoint(textNodes[i],0) == 0)) {
// Create a regular expression object to do the searching
var reSearch = new RegExp(searchString,'gmi'); // Set it to 'g' - global (finds all instances), 'm' - multiline (searches more than one line), 'i' - case insensitive
var stringToSearch = textNodes[i].textContent;
var newRange = null;
while(reSearch(stringToSearch)) { // While there are occurrences of the searchString
// Test if the index is after the currentRange's position
if(reSearch.lastIndex - searchString.length > currentRange.startOffset) {
// This is the new search position - empty the old selection and add the new selection range
theSelection.removeAllRanges();
newRange = document.createRange();
newRange.setStart(textNodes[i],reSearch.lastIndex - searchString.length); // Start node and index of the selection range
newRange.setEnd(textNodes[i],reSearch.lastIndex); // End node and index of the selection
theSelection.addRange(newRange); // Add the node to the document's current selection
break; // We're not interested in the other results, so break out of this while loop.
}
}
if(newRange) break; // If we found a new range, break out of this for loop, cos there's nothing more to do.
else continue; // Otherwise continue
}
// If this text node is after the current one, search to see if it has any occurrences of the searchString
else if(currentRange.comparePoint(textNodes[i],0) == 1) {
// Create a regular expression object to do the searching
var reSearch = new RegExp(searchString,'gmi'); // Set it to 'g' - global (finds all instances), 'm' - multiline (searches more than one line), 'i' - case insensitive
var stringToSearch = textNodes[i].textContent;
// If we had a find, use it
if(reSearch(stringToSearch)) {
// This is the new search position - empty the old selection and add the new selection range
theSelection.removeAllRanges();
newRange = document.createRange();
newRange.setStart(textNodes[i],reSearch.lastIndex - searchString.length); // Start node and index of the selection range
newRange.setEnd(textNodes[i],reSearch.lastIndex); // End node and index of the selection
theSelection.addRange(newRange); // Add the node to the document's current selection
break; // We're not interested in the other results, so break out of this while loop.
} else continue;
}
}
}

// If we don't already have a selection, just find the first instance
else {
// Search all text nodes
for(var i = 0; i < textNodes.length; i++) {
// Create a regular expression object to do the searching
var reSearch = new RegExp(searchString,'gmi'); // Set it to 'g' - global (finds all instances), 'm' - multiline (searches more than one line), 'i' - case insensitive
var stringToSearch = textNodes[i].textContent;
if(reSearch(stringToSearch)) { // If there are occurrences of the searchString
// This is the new search position - empty the old selection and add the new selection range
theSelection.removeAllRanges();
// Add the new selection range
var thisRange = document.createRange();
thisRange.setStart(textNodes[i],reSearch.lastIndex - searchString.length); // Start node and index of the selection range
thisRange.setEnd(textNodes[i],reSearch.lastIndex); // End node and index of the selection
theSelection.addRange(thisRange); // Add the node to the document's current selection
break; // We're done
}
}
}
}
else if(document.selection) { // Internet Explorer
theSelection = document.selection;
var currentRange = theSelection.createRange();
// Empty the current selection
theSelection.empty();
if(currentRange && currentRange.text && currentRange.text.match(eval('/'+searchString+'/i'))) {
// Move start position of range past this word
currentRange.moveStart('word');
// Move end position to end of document
currentRange.moveEnd('textEdit');
// Search again
if(currentRange.findText(searchString)) {
// Select
currentRange.select();
return true;
}
return false;
} else {
// Get a new range
var searchRange = document.body.createTextRange();
// Make it encompass the whole document
searchRange.expand('textedit');
// Find the first occurrence of the searchString
if(searchRange.findText(searchString)) {
// Select
searchRange.select();
return true;
} else {
return false;
}
}
} else alert("Sorry your browser doesn't support a supported selection object");
}
}

// Recursively find all text nodes within an element
function findTypeNodes(elem,type) {
// Remove superfluous text nodes and merge adjacent text nodes
elem.normalize();

var typeNodes = new Array();
// Search all children of this element to see which ones are the right type of node
for(var nodeI = 0; nodeI < elem.childNodes.length; nodeI++) {
if(elem.childNodes[nodeI].nodeType == type) typeNodes.push(elem.childNodes[nodeI]); // If it is a the right type of node, add it to the array
else {
// If not a the right type of node, search it in turn
typeNodes = typeNodes.concat(findTypeNodes(elem.childNodes[nodeI],type));
}
}
return typeNodes; // return the array
}

// Multiple onload function created by: Simon Willison
// http://simon.incutio.com/archive/2004/05/26/addLoadEvent
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}

addLoadEvent(function() {
// Create a button
var theInput = document.getElementById('searchInput');
var theButton = document.getElementById('performSearch');
var elementToSearch = document.body; // Use getElementById('yourIDName') to only allow search for a specific id.
theButton.onclick = function() { // Set the onclick function
performSingleSearch(theInput,elementToSearch);
}
});
</script>


<fieldset style="width: 240px;">
<legend>Search the page</legend>
<input type="text" id="searchInput"><button id="performSearch">search</button>
</fieldset>[/codebox]

arkadaşlar buldum bu javascript kodu ile sitenizde öyle bir arama yaptırabilirsiniz.
Teşekkürler.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...