• 0

Need Help with simple java script code


Question

Hi

I need help with a simple code

I want a code that makes a photo appeares when I hit left click on the browser

and the previous one remains

as a copy paste

How to make it?

Do I have to use coords for such a page?

I can make it changed position onclick , but I want it to be copied also

Edited by ReMad
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

How about this.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>Scriptmedo</title>
<style type="text/css">
<!--

	body { width: 100%; height: 100% }

//-->
</style>
<script type="text/javascript">
<!--

var IE = (document.all ? true : false);

var image_path = 'test.png';

function init()
{
	if (IE) {
		body.attachEvent("onclick", mouseClick);
	}else {
		document.addEventListener("click", mouseClick, true);
	}
}

function mouseClick(e) {
	if (IE) {
		e = window.event;
		addimage(e.clientX, e.clientY);
	}else {
		addimage(e.pageX, e.pageY);
	}
}

function addimage(x, y)
{
	if (document.getElementById) {

		new_div = document.createElement('div');
		document.getElementById('body').appendChild(new_div)

		new_img = new Image;
		new_img.src = image_path;

		var img_tag = '<img src="' + image_path + '" alt="' + image_path + '" />';

		new_div.style.position = "absolute";
		new_div.style.top = y - (new_img.height / 2);
		new_div.style.left = x - (new_img.width / 2);
		new_div.innerHTML = img_tag;

		delete new_img;
	}
}

//-->
</script>
<body id="body" onload="init()">
</body>
</html>

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.