Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

jQuery za xpath putanju - problem

[es] :: Javascript i AJAX :: jQuery za xpath putanju - problem

[ Pregleda: 1626 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Vlada A

Član broj: 271370
Poruke: 142
*.dynamic.isp.telekom.rs.

Sajt: bedbids.com


+3 Profil

icon jQuery za xpath putanju - problem16.12.2011. u 20:12 - pre 150 meseci
Zdravo svima. Imam kod za izvlacenje xpath putanje (javascript) i radi odlicno kada se primenjuje na HTML elementima:

Code:
<script src="http://code.jquery.com/jquery-latest.js"></script> 
//function for xpath location
<script type="text/javascript">
    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;
      };

</script>



Medjutim ono sto meni treba jeste da uzima xpath putanje iz iframe elementa preko jquery koda i da upisuje u polje sa fokusom sto sam pokusao ovim kodom ali ne radi:

Code:
<script type="text/javascript">
    
    $('#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)
        });
    });
</script>



Iframe je na mom domenu i dobijam ga sledecim kodom:


Code:
<?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="me" /> 

    <title>FFF</title> 
<!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="me" /> 

    <title>FFFF</title> 
<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>



GDE BI MOGLA DA BUDE GRESKA U mom jquery kodu za pozivanje funcije getXPath?

 
Odgovor na temu

Nikola Poša
Backend (PHP) developer
Beograd

Član broj: 173839
Poruke: 1616
*.adsl-a-6.sezampro.rs.



+33 Profil

icon Re: jQuery za xpath putanju - problem18.12.2011. u 09:54 - pre 150 meseci
Mislim da ne možeš tako da pristupaš iframe-u... Probaj ovako nešto:
Code:
var iframeDoc = $('iframe#iframe').contents().get(0);
$(iframeDoc).bind('click', function(event) {
    alert(getXPath(event.target));
});


 
Odgovor na temu

Vlada A

Član broj: 271370
Poruke: 142
*.com
Via: [es] mailing liste

Sajt: bedbids.com


+3 Profil

icon Re: jQuery za xpath putanju - problem18.12.2011. u 13:33 - pre 150 meseci
>

--001517476732794e5704b45ddfda
Content-Type: text/html; charset=ISO-8859-2
Content-Transfer-Encoding: quoted-printable

Neznam ali ne moze ni ovako da se pristupa...<br><br><div class="gmail_quote">2011/12/18 Nikola Po�a <span dir="ltr">&lt;<a href="mailto:[email protected]">[email protected]</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Mislim da ne mo�e� tako da pristupa� iframe-u... Probaj ovako ne�to:<br>
<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
<a href="http://www.elitesecurity.org/p3013556" target="_blank">http://www.elitesecurity.org/p3013556</a><br>
<br>
Prijave/odjave: <a href="http://www.elitesecurity.org/pracenje#442459" target="_blank">http://www.elitesecurity.org/pracenje#442459</a><br>
<br>
Ne menjajte sledece dve linije ukoliko odgovarate putem emaila!<br>
esauth:442459:6638300736e88c542b10388c72ba5f1b<br>
 
Odgovor na temu

Vlada A

Član broj: 271370
Poruke: 142
*.dynamic.isp.telekom.rs.

Sajt: bedbids.com


+3 Profil

icon Re: jQuery za xpath putanju - problem18.12.2011. u 13:40 - pre 150 meseci
Nazalost ne moze ni tako :(
 
Odgovor na temu

[es] :: Javascript i AJAX :: jQuery za xpath putanju - problem

[ Pregleda: 1626 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.