javascript - How to Fetch Coordinate Value (x,y) from jQuery Code and Store in NSString? -
div
tag used performing bold, italic, etc. operations in uiwebview
. want fetch position coordinates when user touches div tag through javascript/jquery.
i found code in jsfiddle.
$(document).ready(function(e) { $('#c').click(function(e) { var posx = $(this).position().left, posy = $(this).position().top; var x = e.pagex - posx; var y = e.pagey - posy; alert( (x) + ' , ' + (y)); }); });
#c { width: 100px; height: 100px; cursor: pointer; background: #2f2f2f; position: absolute; top: 50px; color: #fff; font: bold 15px arial; }
<div id="c" style="left:500px;"> position() <br /> mouse <br/> position </div>
how store x
, y
coordinates jquery nsstring
using string evaluating javascript string?
as per uiwebview class reference, need use stringbyevaluatingjavascriptfromstring
, return value javascript function.
this question on stack overflow has few answers go pretty detail. suggest starting there.
update in response comment:
jquery javascript library. fundamentals still apply. return value in jquery (in case, altering function you've provided) need to... well... return value.
var getcoord = function() { var posx = $(this).position().left, posy = $(this).position().top; var x = e.pagex - posx; var y = e.pagey - posy; return (x) + ' , ' + (y); // line returns coordinates }; getcoord(); // call function
Comments
Post a Comment