Right Click Event?
Moderator: General Moderators
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
Right Click Event?
Hi guys,
I appreciate that this would require the use of some javascript, BUT.... would it be possibl to have an email to be sent when a right click is made on an HTML page.
Any help would be appreciated as I do not really have a clue where to start!
Thanks in advance,
Rob.
I appreciate that this would require the use of some javascript, BUT.... would it be possibl to have an email to be sent when a right click is made on an HTML page.
Any help would be appreciated as I do not really have a clue where to start!
Thanks in advance,
Rob.
Re: Right Click Event?
Well, I can tell you where to start; oncontextmenu.
It's a javascript event that detects when right-clicks are pressed... sort of. Different browsers use different numbers for the mouse keys, so it's more reliable to detect when a context menu is shown, rather than when a certain button is pressed. (event.button for a right click is 2, and this MAY work in both FF and IE, but it is likely a less reliable method to determine what you want...)
It's a javascript event that detects when right-clicks are pressed... sort of. Different browsers use different numbers for the mouse keys, so it's more reliable to detect when a context menu is shown, rather than when a certain button is pressed. (event.button for a right click is 2, and this MAY work in both FF and IE, but it is likely a less reliable method to determine what you want...)
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
Re: Right Click Event?
Ok this is where I am at present:
However when I load my page the 'yfunction' code is executing before I have pressed a button. It seems to be excuting opon the page load.
Any ideas?
Thanks,
Rob.
Code: Select all
<script language="javascript">
function click(e) {
if (event.button==2||evetbutton=-3') {
alert("<?php myfunction() ?>");
return true;
}
}
document.onmousedown=click
</script>Any ideas?
Thanks,
Rob.
Re: Right Click Event?
It is triggering when the PHP function is called, which is when the script generates the HTML delivered to the browser. It is not triggered when the page is loaded, it is triggered when PHP is told to generate the page.
Javascript can not directly call PHP. You will need to either set up an AJAX object, or you can do something like have javascript open a popup (with a page to send the mail), wait 50ms, and close the popup. That would work, it would just be... sloppy.
Javascript can not directly call PHP. You will need to either set up an AJAX object, or you can do something like have javascript open a popup (with a page to send the mail), wait 50ms, and close the popup. That would work, it would just be... sloppy.
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
Re: Right Click Event?
Ok that makes sense, php being server side and javascript client side.
I have implemented my code using the window open. how do I autoclose the windwos after a set period though? Also my code will only implment if the user aloows the popup. Is that ocrrect, I am guessing there is no way around this?
Thanks,
Rob.
I have implemented my code using the window open. how do I autoclose the windwos after a set period though? Also my code will only implment if the user aloows the popup. Is that ocrrect, I am guessing there is no way around this?
Thanks,
Rob.
Re: Right Click Event?
You can use an AJAX object request to call the script.
To set a delay:
setTimeout(window.close,delaytime)
should do the trick.
To set a delay:
setTimeout(window.close,delaytime)
should do the trick.
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
Re: Right Click Event?
Will the AJAX object request by-pass the popup blocker?
Any tips regarding AJAX code, I've not used it before.
Thanks,
Rob.
Any tips regarding AJAX code, I've not used it before.
Thanks,
Rob.
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
Re: Right Click Event?
Rob,
Check out to help you learn some of the fundamentals http://www.ajaxf1.com/tutorial/ajax-php.html . Do some google on ajax with php tutorials to find more info.
Check out to help you learn some of the fundamentals http://www.ajaxf1.com/tutorial/ajax-php.html . Do some google on ajax with php tutorials to find more info.
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
Re: Right Click Event?
Awesome thanks guys the AJAX work likea treat. I have it working as I wish except for the auto close. What is the name of the function that does this?
THANK YOU!
Rob.
THANK YOU!
Rob.
Re: Right Click Event?
window.close()