Page 1 of 1
Right Click Event?
Posted: Sat Jan 09, 2010 2:16 pm
by spacebiscuit
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.
Re: Right Click Event?
Posted: Sat Jan 09, 2010 4:18 pm
by omniuni
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...)
Re: Right Click Event?
Posted: Sat Jan 09, 2010 4:53 pm
by spacebiscuit
Ok this is where I am at present:
Code: Select all
<script language="javascript">
function click(e) {
if (event.button==2||evetbutton=-3') {
alert("<?php myfunction() ?>");
return true;
}
}
document.onmousedown=click
</script>
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.
Re: Right Click Event?
Posted: Sat Jan 09, 2010 5:10 pm
by omniuni
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.
Re: Right Click Event?
Posted: Sat Jan 09, 2010 5:44 pm
by spacebiscuit
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.
Re: Right Click Event?
Posted: Sat Jan 09, 2010 8:25 pm
by omniuni
You can use an AJAX object request to call the script.
To set a delay:
setTimeout(window.close,delaytime)
should do the trick.
Re: Right Click Event?
Posted: Sun Jan 10, 2010 4:39 am
by spacebiscuit
Will the AJAX object request by-pass the popup blocker?
Any tips regarding AJAX code, I've not used it before.
Thanks,
Rob.
Re: Right Click Event?
Posted: Sun Jan 10, 2010 9:18 am
by Charles256
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.
Re: Right Click Event?
Posted: Mon Jan 11, 2010 7:27 am
by spacebiscuit
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.
Re: Right Click Event?
Posted: Mon Jan 11, 2010 9:41 am
by omniuni
window.close()