2

I have a csv file containing the coordinates. I also have the HTML for the webpage. I am hosting the webpage on my localhost. I want to know the elements which are present at the coordinates and output details into a new csv file. I have following PHP script inside my HTML file.

 for($i=1;$i<=10;$i++)
    {
     echo '<script>var elem= document.elementFromPoint('.$csv[$i][1].','.$csv[$i]2].');alert(a);</script>
    }

But now how to access this variable elem from PHP. Can I output CSV from javascript?

Is there any other way to get the coordinates from CSV and output element details ? Any help is highly appreciated

dulla
  • 136
  • 1
  • 1
  • 11

1 Answers1

1

You could just pass the array to javascript, operate on it and then return it via Ajax.

var elements = [];
var coordinates = <?php echo json_encode($csv); ?>
coordinates.forEach(function (coordinate) {
    var element = document.elementFromPoint(coordinate[0], coordinate[1]);
    elements.push(element)); // I imagine you would want some attribute from the element here.
});
// Then pass it back to the server
$.post('index.php', elements); // Or however it is you are doing you ajax requests.

Alternatively, I imagine you could use node.js to locally render the DOM and never use a browser. But that would not answer your question since you would have to stop using PHP.

UPDATE: Regarding the CSV, it is completely a different question. But yeah, you could output the info in a csv download prompt. See:

How to export JavaScript array info to csv (on client side)?

Community
  • 1
  • 1
fos.alex
  • 5,317
  • 4
  • 16
  • 18