Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Problem with people spamming onKey.
Old 08-18-2009, 04:46 PM Problem with people spamming onKey.
Novice Talker

Posts: 5
Name: Alev
Trades: 0
Code:
<script type="text/javascript">
document.onkeypress=keyevent;
    function keyevent(e){
        var c;
        var target;
        var altKey;
        var ctrlKey;
        if (window.event != null) {
            c=String.fromCharCode(window.event.keyCode).toUpperCase();
            altKey=window.event.altKey;
            ctrlKey=window.event.ctrlKey;
        }else{
            c=String.fromCharCode(e.charCode).toUpperCase();
            altKey=e.altKey;
            ctrlKey=e.ctrlKey;
        }
        if (window.event != null)
            target=window.event.srcElement;
        else
            target=e.originalTarget;
        if (target.nodeName.toUpperCase()=='INPUT' || target.nodeName.toUpperCase()=='TEXTAREA' || altKey || ctrlKey){
        }else{
        if (theyhit != true)
            {
            var theyhit = true;
                if (c == '1') { window.location='pve.php?a=1$macronig'; }";
                if (c == '2') { window.location='pve.php?a=2$macronig'; }";
                if (c == '3') { window.location='pve.php?a=3$macronig'; }";
                if (c == '4') { window.location='pve.php?a=4$macronig'; }";
                if (c == '5') { window.location='pve.php?a=5$macronig'; }";
                ?>
            }    
        }
    }
    
    </script>
Hello, the problem with the code above is that people are spamming their 1-5 keys and making a big server mess. (unintentionally) So I tried, with my basic understanding of javascript, to make it so that if they hit any key, it sets the var "theyhit" to true, and then it won't allow them again. But it simply doesn't work... and I have no idea why, so if anyone knows, that'd be wonderful!

-- V
Vael Victus is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-23-2009, 02:07 AM Re: Problem with people spamming onKey.
Novice Talker

Posts: 5
Name: Alev
Trades: 0
Hey I'm just gonna bump this up now, see if there are any answers.
Vael Victus is offline
Reply With Quote
View Public Profile
 
Old 08-23-2009, 08:46 AM Re: Problem with people spamming onKey.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
spamming onKey ?????????????

Fix it SERVER SIDE not client side because once the window.location has been changed the variables have all been recreated as the page reloads.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-23-2009, 01:10 PM Re: Problem with people spamming onKey.
Novice Talker

Posts: 5
Name: Alev
Trades: 0
Erm... I'm not entirely sure what you mean. I just want to set a variable when someone hits a key, and thus the next time they hit a key, it won't send the action again. It's not a server-side problem, it's just them holding down the key or double-hitting it.
Vael Victus is offline
Reply With Quote
View Public Profile
 
Old 08-23-2009, 02:38 PM Re: Problem with people spamming onKey.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It won't help!!!

set the variable by all means.

BUT as soon as the page location changes, the variable value will be GONE
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-23-2009, 03:51 PM Re: Problem with people spamming onKey.
Novice Talker

Posts: 5
Name: Alev
Trades: 0
But that is okay, because it should do that. It loads the page again, they hit the key again to go to another page. The problem is on that one page, they are hitting it twice, and sending the request twice.
Vael Victus is offline
Reply With Quote
View Public Profile
 
Old 08-24-2009, 01:04 PM Re: Problem with people spamming onKey.
Novice Talker

Posts: 5
Name: Alev
Trades: 0
Finally figured it out. Put var theyhit = false; under document.onkeypress=keyevent;

Pretty funny that a guy - a moderator, no less - who has almost 20,000 posts couldn't help me with the most amateur of problems. Perhaps he didn't read the post or javascript very well because I have 1/10,000 the posts he has. Not a very newbie-friendly forum. I won't be returning, which I'm sure you won't mind, because who needs a noob like me obviously. Just a friendly suggestion to reconsider your poor attitude. Cheers.
Vael Victus is offline
Reply With Quote
View Public Profile
 
Old 08-24-2009, 05:37 PM Re: Problem with people spamming onKey.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Chill out Alev....
I honestly have not understood neither what you wanted to do without re-reading several time your posts.

Chris may be a bit rough, but it's what happens when you deal with the "give me the code, I don't want to search" guys.

Not that you are.
But in the end, we tend to give more time towards peoples with questions we understand easily.

We do (and I'm sure I talk for most of us) try to be the most open and insightful we can, but I'm sure you can understand that sometime, the mood is just not there.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Problem with people spamming onKey.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24358 seconds with 12 queries