Pogledajte određenu poruku
Staro 17. 12. 2011.   #1
AdriaMart
expert
Expert
 
Avatar AdriaMart
 
Datum učlanjenja: 15.03.2011
Poruke: 518
Hvala: 16
20 "Hvala" u 17 poruka
AdriaMart is on a distinguished road
Default Selektovanje elemenata

Imam funkciju getXPath preko koje dobijam xpath putanju - evo koda:

Kôd:
function getXPath(node, path) {
        path = path || [];
        if(node.parentNode) {
          path = getXPath(node.parentNode, path);
        }

        if(node.previousSibling) {
          var count = 1;
          var sibling = node.previousSibling
          do {
            if(sibling.nodeType == 1 && sibling.nodeName == node.nodeName) {count++;}
            sibling = sibling.previousSibling;
          } while(sibling);
          if(count == 1) {count = null;}
        } else if(node.nextSibling) {
          var sibling = node.nextSibling;
          do {
            if(sibling.nodeType == 1 && sibling.nodeName == node.nodeName) {
              var count = 1;
              sibling = null;
            } else {
              var count = null;
              sibling = sibling.previousSibling;
            }
          } while(sibling);
        }

        if(node.nodeType == 1) {
          path.push(node.nodeName.toLowerCase() + (node.id ? "[@id='"+node.id+"']" : count > 0 ? "["+count+"]" : ''));
        }
        return path;
      };
zatim mi je @webarto pomogao oko koda za prikazivanje Iframe-a na svom domenu koju sam ja malo izmenio tako da dobijem iframe sajta ciji URL upisem u tekst polju:

Kôd:
<?php 

error_reporting(E_ALL ^ E_NOTICE); 

$url = $_GET['url']; 

if( ! empty($url)) 
{ 
    $data = file_get_contents($url); 
     
    $data = str_replace('<head>', '<head><base href="'.$url.'" /></base>', $data); 
     
    $data = preg_replace('#<script(.*?)>(.*?)</script>#is', '', $data); 
    $data = preg_replace('#<iframe(.*?)></iframe>#is', '', $data); 
     
    $data .=  
    ' 
    <script src="http://code.jquery.com/jquery-latest.js"></script> 
    <script> 
    $("div").each(function(i){ 
        if($(this).css("position") == "fixed") $(this).css("display", "none"); 
    }); 
    </script> 
    ' 
    ; 
     
    die($data);  
} 

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    <meta name="author" content="Webarto" /> 

    <title>AdriaMart</title> 
<script src="http://code.jquery.com/jquery-latest.js"></script> 
<style type="text/css"> 
<!-- 
iframe{width:100%;height:400px;} 
--> 
</style> 

</head> 
<body> 

<!-- ... -->
<input id="iframe_url" name="" type="text" />
<input id="iframe_button" name="" type="button" />
<iframe id="iframe" src="?url=http://kupime.com"></iframe>
<script type="text/javascript">
  document.getElementById('iframe_button').onclick = function () {
    document.getElementById('iframe').src = '?url=' + document.getElementById('iframe_url').value;
  };
</script>
<!-- ... -->
//Textfields for xpath location to write inside them
<input id="" name="myinput" type="text" value="">
<input id="" name="myinput" type="text" value="">
<input id="" name="myinput" type="text" value="">



</body> 
</html>

i na kraju sam ja dodao svoju jquery funkciju koja bi trebalo da selektuje elemente unutar IFrame-a i da ih upisuje u text polje koje je u fokusu:

Kôd:
$('#iframe').ready(function () {
        var selectedtextbox;
$('input[name="myinput"]').focus(function(){selectedtextbox=$(this);});
        $('p, li, a, href').click(function () { 
           var xpath = getXPath(this);
            selectedtextbox.val(xpath)
        });
    });
ALI NE RADI. ZBOG CEGA NE VIDIM STVARNO.


inace na obicnom html-u (znaci kada nije u iframe-u) ova funcija radi ekstra, medjutim za iframe nece. Da li je mozda problem u cross-domain security ili ???
__________________
I'm not sexy and I know IT!

Poslednja izmena od AdriaMart : 17. 12. 2011. u 01:00.
AdriaMart je offline   Odgovorite uz citat