Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6955503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:44:41+00:00 2026-05-27T14:44:41+00:00

Possible Duplicate: Get xpath location of element in iframe(iframe from my domain) I have

  • 0

Possible Duplicate:
Get xpath location of element in iframe(iframe from my domain)

I have a javascript function to get xpath as result (getXPath) and below is the code. Also I have a an external site in iframe but I show him when I use proxy (code is below). And I have a jquery function to show me xpath when I click on some element in iframe but Dont work. What is problem:

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="Webarto" /> 

    <title>AdriaMart</title> 

<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>

//function to get  xpath location and write in textfield in focus
***<script>

    $('#iframe').ready(function () {
        var selectedtextbox;
$('input[name="myinput"]').focus(function(){selectedtextbox=$(this);});
        $('div, p, li, a, href').click(function () { 
           var xpath = getXPath(this);
            selectedtextbox.val(xpath)
        });
    });
</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> 

***

    $('#iframe').ready(function () {
        var selectedtextbox;
$('input[name="myinput"]').focus(function(){selectedtextbox=$(this);});
        $('div, p, li, a, href').click(function () { 
           var xpath = getXPath(this);
            selectedtextbox.val(xpath)
        });
    });
</script>***
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:44:42+00:00Added an answer on May 27, 2026 at 2:44 pm

    There are 3 issues.

    1. the iframe-element is not accessible at this point(the function is placed above the iframe, the #iframe-element is still unknown)
    2. ready will fire when the current document is ready, not the document within the iframe. Use load instead

    3. you need to set the document within the iframe as context-argument


    //wait for ready in the current document to have access to #iframe
    $(function()
      {
        $('#iframe')
          //observe the load-event of the iframe-element
          .on('load',
              function () 
              {
                //set a default-input to avoid errors
                var selectedtextbox=$('input[name="myinput"]:eq(0)');
                $('input[name="myinput"]')
                  .focus(function(){selectedtextbox=$(this);});
                //Note the 2nd argument here, 
                //it sets the contextof $() to the document inside the iframe
                $('div, p, li, a, href',
                  this.contentWindow.document)
                    .click(function () 
                           { 
                              var xpath = getXPath(this);
                              selectedtextbox.val(xpath)
                           });
                });
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I get the name of function inside a JavaScript function?
Possible Duplicate: Get a function's arity Say I have: function a(x) {}; function b(x,y)
Possible Duplicate: jQuery: get the file name selected from <input type=file /> I have
Possible Duplicate: How to get a DOM Element from a JQuery Selector I can
Possible Duplicate: Get first element of array Convert array to string php I have
Possible Duplicate: Get property of object in JavaScript If I have the following: var
Possible Duplicate: Get query string values in JavaScript I am writing a jQuery function
Possible Duplicate: Get all files from VSS for a given date? I need to
Possible Duplicate: Return value from thread I want to get the free memory of
Possible Duplicate: get image from base64 string I tried header('Content-Type: image/png'); echo base64_decode($data);` But

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.