是否可以使用PHP获取图像鼠标单击位置?

时间:2022-11-28 20:52:24

Basically what the title says...

基本上标题是什么......

I need to have an image that when clicked, I call script.php for instance and in that PHP script file, I get the image coordinates where the mouse was clicked.

我需要有一个图像,当点击时,我调用script.php,在那个PHP脚本文件中,我得到了点击鼠标的图像坐标。

Is this possible?

这可能吗?

EDIT:
After a couple of answers I realized I didn't describe my problem correctly... The thing is, I don't have total control over the HTML. The control I have for the image and the image link is the control BBCode provides me.

编辑:经过几个答案,我意识到我没有正确描述我的问题......事实是,我没有完全控制HTML。我对图像和图像链接的控制是BBCode为我提供的控件。

Basically want I want to do is to have a forum signature with links to various sections on my website. You could argue I could use multiple images but most forums limit how much you can type for the signature, which is not enough for multiple images.

基本上我想要的是拥有一个论坛签名,链接到我网站上的各个部分。您可以说我可以使用多个图像,但大多数论坛会限制您为签名键入的内容,这对于多个图像来说是不够的。

So, I will only be able to do something like this:

所以,我只能做这样的事情:

[url=http://www.mydomain.com/script.php]
[img]http://www.mydomain.com/signature.jpg[/img]
[/url]

Which translates to something like this:

这意味着:

<a href="http://www.mydomain.com/script.php">
<img src="http://www.mydomain.com/signature.jpg" />
</a>

7 个解决方案

#1


4  

If you can't:

如果你不能:

  1. use JavaScript, or
  2. 使用JavaScript,或

  3. use input type="image", or
  4. 使用input type =“image”,或

  5. add any attributes to your img tag (to do things like create an image map)
  6. 添加任何属性到您的img标签(做创建图像映射的事情)

then, no, you won't be able to do what you describe.

那么,不,你将无法做你所描述的。

#2


3  

If you use an input type="image", which works like a button, it will send you x and y coordinates of the mouse click (submits form too).

如果你使用输入类型=“图像”,它就像一个按钮,它将发送鼠标点击的x和y坐标(也提交表单)。

More info here: http://www.htmlhelp.com/reference/html40/forms/input.html#image

更多信息请访问:http://www.htmlhelp.com/reference/html40/forms/input.html#image

Long time since I used it, but I did make it work for a "where's the ball?" competition on a site many years ago.

自从我使用它以来很长一段时间,但我确实让它适用于“哪里有球?”很多年前在一个网站上的竞争。

Update:

Sounds like the environment is just too limited to do what you want. If the forum lets you do an image map that would work, but I doubt they'd let you. Only other things I could think of would be flash or javascript, similarly, they prob won't allow them. You need something with a little more smarts than an image and an anchor to make this work.

听起来环境太有限了,无法做到你想要的。如果论坛允许你做一个可行的图像地图,但我怀疑他们会让你。只有我能想到的其他东西都是flash或javascript,同样,他们也不会允许它们。你需要一些比图像和锚点更聪明的东西来使这项工作。

#3


3  

if you set the image input name="foo", then $\_POST['foo\_x'] and $\_POST['foo\_y'] will be set to the image coordinates.

如果你设置图像输入name =“foo”,那么$ \ _ POST ['foo \ _x']和$ \ _POST ['foo \ _y']将被设置为图像坐标。

#4


1  

You could try using W3C Image Maps

您可以尝试使用W3C图像映射

Image maps allow authors to specify regions of an image or object and assign a specific action to each region (e.g., retrieve a document, run a program, etc.) When the region is activated by the user, the action is executed.

图像映射允许作者指定图像或对象的区域并为每个区域分配特定动作(例如,检索文档,运行程序等)。当用户激活该区域时,执行动作。

But on a forum in BBCode, I really don't think you're going to be able to get what you're after.

但是在BBCode的一个论坛上,我真的不认为你能够得到你想要的东西。

#5


0  

This will not be possible unless you can add inline event handlers to the url in bbcode.

除非您可以在bbcode中的url中添加内联事件处理程序,否则这是不可能的。

#6


0  

Another solution, though not for BBCode is to use the ismap attribute for img. But may be valuable to others needing exact coordinates. Example:

另一种解决方案,虽然不适用于BBCode,但是使用img的ismap属性。但对于需要精确坐标的人来说可能很有价值。例:

<a href="link.html"><img src="shapes.jpg" alt="Shapes" ismap="ismap"/></a>

The x and y coordinates will be passed as GET parameters to link.html

x和y坐标将作为GET参数传递给link.html

#7


-2  

You can use an ajax request when "onclick" is performed to send a request to "script.php". Otherwise I would read up on php, which is a server-side language.

执行“onclick”时,可以使用ajax请求向“script.php”发送请求。否则我会读到php,这是一种服务器端语言。

#1


4  

If you can't:

如果你不能:

  1. use JavaScript, or
  2. 使用JavaScript,或

  3. use input type="image", or
  4. 使用input type =“image”,或

  5. add any attributes to your img tag (to do things like create an image map)
  6. 添加任何属性到您的img标签(做创建图像映射的事情)

then, no, you won't be able to do what you describe.

那么,不,你将无法做你所描述的。

#2


3  

If you use an input type="image", which works like a button, it will send you x and y coordinates of the mouse click (submits form too).

如果你使用输入类型=“图像”,它就像一个按钮,它将发送鼠标点击的x和y坐标(也提交表单)。

More info here: http://www.htmlhelp.com/reference/html40/forms/input.html#image

更多信息请访问:http://www.htmlhelp.com/reference/html40/forms/input.html#image

Long time since I used it, but I did make it work for a "where's the ball?" competition on a site many years ago.

自从我使用它以来很长一段时间,但我确实让它适用于“哪里有球?”很多年前在一个网站上的竞争。

Update:

Sounds like the environment is just too limited to do what you want. If the forum lets you do an image map that would work, but I doubt they'd let you. Only other things I could think of would be flash or javascript, similarly, they prob won't allow them. You need something with a little more smarts than an image and an anchor to make this work.

听起来环境太有限了,无法做到你想要的。如果论坛允许你做一个可行的图像地图,但我怀疑他们会让你。只有我能想到的其他东西都是flash或javascript,同样,他们也不会允许它们。你需要一些比图像和锚点更聪明的东西来使这项工作。

#3


3  

if you set the image input name="foo", then $\_POST['foo\_x'] and $\_POST['foo\_y'] will be set to the image coordinates.

如果你设置图像输入name =“foo”,那么$ \ _ POST ['foo \ _x']和$ \ _POST ['foo \ _y']将被设置为图像坐标。

#4


1  

You could try using W3C Image Maps

您可以尝试使用W3C图像映射

Image maps allow authors to specify regions of an image or object and assign a specific action to each region (e.g., retrieve a document, run a program, etc.) When the region is activated by the user, the action is executed.

图像映射允许作者指定图像或对象的区域并为每个区域分配特定动作(例如,检索文档,运行程序等)。当用户激活该区域时,执行动作。

But on a forum in BBCode, I really don't think you're going to be able to get what you're after.

但是在BBCode的一个论坛上,我真的不认为你能够得到你想要的东西。

#5


0  

This will not be possible unless you can add inline event handlers to the url in bbcode.

除非您可以在bbcode中的url中添加内联事件处理程序,否则这是不可能的。

#6


0  

Another solution, though not for BBCode is to use the ismap attribute for img. But may be valuable to others needing exact coordinates. Example:

另一种解决方案,虽然不适用于BBCode,但是使用img的ismap属性。但对于需要精确坐标的人来说可能很有价值。例:

<a href="link.html"><img src="shapes.jpg" alt="Shapes" ismap="ismap"/></a>

The x and y coordinates will be passed as GET parameters to link.html

x和y坐标将作为GET参数传递给link.html

#7


-2  

You can use an ajax request when "onclick" is performed to send a request to "script.php". Otherwise I would read up on php, which is a server-side language.

执行“onclick”时,可以使用ajax请求向“script.php”发送请求。否则我会读到php,这是一种服务器端语言。