473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

copy & paste

Hi,

I would like to copy and paste a selected item on a web page I already
've a context menu when the user rigth click on an item.

I would like to draw a rectangle who carry about current mouse position
until the user click left to a position.

I know how to draw a rectangle and how to get mouse position, now I need
to know how can I draw the rectangle (move it with mouse coordinate)
until user click a point on the web page.

Thanks in advance :)
Jul 23 '05 #1
1 2051
"Alexandre Jaquet" <al***@floor.ch> wrote in message
news:d2**********@news.hispeed.ch...
Hi,

I would like to copy and paste a selected item on a web page I already
've a context menu when the user rigth click on an item.

I would like to draw a rectangle who carry about current mouse position
until the user click left to a position.

I know how to draw a rectangle and how to get mouse position, now I need
to know how can I draw the rectangle (move it with mouse coordinate)
until user click a point on the web page.

Thanks in advance :)

I don't know if this will help you.

It draws a rectangle after the mouse is clicked twice.

A third click "hides" it by setting the rectangle's border to white.

<html>
<head>
<title>rectangle.htm</title>
<script type="text/javascript">

// JavaScript Capture Mouse X-Y Position Script
// http://www.codelifter.com/main/javas...position1.html

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Set-up to use getMouseXY function onMouseDown
document.onmousedown = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft
tempY = event.clientY + document.body.scrollTop
} else { // grab the x-y pos.s if browser is NS
tempX = e.pageX
tempY = e.pageY
}
// catch possible negative values in NS4
if (tempX < 0){tempX = 0}
if (tempY < 0){tempY = 0}
// draw rectangle with a pair of coordinates
rectangle();
return true
}

// Rectabnle code below:

var i = -1;
var x = [0,0];
var y = [0,0];

function rectangle() {
i++;
var d = document.getElementById("rect");
// reset on third mouse click
if (i > 1) {
i = -1;
x = [0,0];
y = [0,0];
d.style.borderColor = "#FFF";
document.body.style.cursor = "default";
window.status = "";
return;
}
document.body.style.cursor = "crosshair";
// get mouse X,Y coordinates
x[i] = tempX;
y[i] = tempY;
// status bar for testing
window.status = x[0] + "," + y[0] + " : " + x[1] + "," + y[1];
if (i != 1) return;
// calculate left, top, width and height
var xl, yt, xx, yy;
(x[0] < x[1]) ? xl = x[0] : xl = x[1];
(y[0] < y[1]) ? yt = y[0] : yt = y[1];
(x[0] < x[1]) ? xx = x[1]-x[0] : xx = x[0]-x[1];
(y[0] < y[1]) ? yy = y[1]-y[0] : yy = y[0]-y[1];
// draw rectangle
d.style.borderWidth = "1px";
d.style.borderColor = "#000";
d.style.borderStyle = "solid";
d.style.position = "absolute";
d.style.left = xl+"px";
d.style.top = yt+"px";
d.style.width = xx+"px";
d.style.height = yy+"px";
// status bar for testing
window.status += " = " + xx + " x " + yy + " pixels";
return true;
}
</script>
</head>
<body>
<div id="rect"></div>
</body>
</html>

I don't doubt that there's a better way to do this.
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nelgonde | last post by:
Apologies for the basic nature of this question but I'm very inexperienced in Java. I've been given the task of disabling the cut/copy/paste functions (Ctrl-X,C & V) in our java dialogs and...
1
by: tabonni | last post by:
Hi all I want to create an ASP page, which can copy the real PDF files into the clipboard and then the user can paste it in Outlook message as attachments(it's like inserting attachments) My...
5
by: tabonni | last post by:
Hello All I am creating an ASP page. There are a list of filename and checkbox next to it. When user checked all the documents they want and click ADD TO CLIPBOARD button. All filepaths will be...
1
by: Tomomichi Amano | last post by:
Hello. I was wondering how to paste-copy-cut-delete at a SELECTED SPOT in a textBox. Thanks in advance.
6
by: NuB | last post by:
I have a winform and a menu on the form, It allows the users to copy and paste text from text boxes. I never had to do this before, how can I copy and paste text from one box to another?
0
by: Mr. Murad Jamal | last post by:
hi guys, I have a textbox & a button in an .aspx page, when I hit the button i want a selected text to be copied to the clipboard AND paste it into the last cursor position on the textbox BOTH AT...
6
by: roopashree | last post by:
hi, currently I am able to cut,copy and paste images for only one image. Suppose I have 4 images-then I should group all the images so that I can cut/copy all 4 images and paste them. How...
6
by: rakeshvthu | last post by:
hi all, can we disable the copy and paste option in edit menu bar of browser my customer does not want copying using any technique so can any one help how to disable that options copy and...
0
by: kavi2012 | last post by:
Hi I used the following function to disable the cut, Copy & paste in the Textbox. It works fine for me when I use ctrl+C,ctrl+X & ctrl+V. function disable(e) { if(event.ctrlKey) { ...
5
by: deve8ore | last post by:
Hello, I have a Word document called (), a named range that will open up a new Word doc dependent on what a user selects in Excel. Could someone please guide me on how to set up VBA code to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.