Displaying mouse coordinates for embedded SVG graph

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
skylark2
Forum Commoner
Posts: 32
Joined: Wed Jun 16, 2010 6:00 am

Displaying mouse coordinates for embedded SVG graph

Post by skylark2 »

Hi folks,

I have a nasty feeling that <embed> may work differently to other HTML elements here. My code works fine for any element which isn't my graph :(

Any suggestions?

Code: Select all

<script type="text/javascript">

window.onload = init;

function init(){
	document.getElementById("graph").onmousemove = mousemove;
}
function mousemove(evt){
	if(!evt){
		evt = window.event;
	}
	document.getElementById("coords").innerHTML = "X = " + evt.clientX + ", Y = " + evt.clientY;
}
</script>
And then in the embed line I have id="graph". It's an SVG file I'm embedding.

If I use the id of the fieldset which has the graph and a bunch of other stuff in, I get coordinates when I'm pointing at anything which isn't the graph, which is why I'm suspicious that embed is different...do I need the Javascript in the svg file instead?

I'm pretty new to Javascript - can anyone point me at an example?

(Not worried about the actual values I'm displaying yet - I'm aware that there are browser incompatibilites and so on. I'm just trying to get something to display at this stage.)
Post Reply