0

I need to execute a certain JavaScript when accesing the custom URL.

At this time the code behind the button that triggers the JavaScript that I need to be ran is this:

  <a class="button" href="#" 

  onclick="new Request.HTML({
  method: 'post',
  url: '/ro/somefolder/anotherfolder',
  data: {'user_id': 777, 'score': 1, 'redirect': '1'},
  update: $('vote_user_777'),
  evalScripts: true
}).send();return false;">

<img src="/images/game/thumbsup.gif" alt="vote">
</a>

</span>
</p>

2
  • Could you be a little more specific as to what you're problem is? I'm sorry, I'm having difficulty understanding what's wrong. Commented May 14, 2009 at 18:17
  • I said that on the website there is a button which when pressed triggers that JavaScript, all i want is a custom URL ( page URL + something ) to execute that JavaScript, the second is accesed. Commented May 14, 2009 at 19:10

2 Answers 2

2

You didn't say what problem you were experiencing, but the syntax looks like the MooTools library.

So I put together a little Javascript that should work, and is more in line with MooTools style.

  window.addEvent('domready',function() {
    var request = new Request.HTML({
        method: 'post',
        url: '/ro/somefolder/anotherfolder',
        data: {'user_id': 777, 'score': 1, 'redirect': '1'},
        update: $('vote_user_777'),
        evalScripts: true
    });
    $$('a.button').addEvent('click',function(e) {
        e.stop();
        request.send();
    });
});
Sign up to request clarification or add additional context in comments.

Comments

0

If you're referring to embedding your JavaScript in a URL rather than attaching it as an event handler, you could do something like this:

<a href="javascript:void(new Request.HTML({...}).send())">

Using the void() function ensures that nothing is returned so that the browser does not navigate away from the current page.

4 Comments

The return false statement in his function already takes care of that.
Yes, but if he's trying to embed his script in a URL, returning false will either generate an error or take you to a page named "false". When using a javascript: URL, you should wrap it in void() instead.
Actually, when the onclick handler returns false, it doesn't execute it's default, which is traveling to the href.
Yes… I realize that. You'll note that the example code I provided doesn't have an onclick handler. This is instead of an onclick handler, as stated in my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.