Lewis Denny
Lewis Denny

Reputation: 669

Open URL with a button on a webpage

Im tying to make a simple site that will control my android phone using a combination of tasker and autoremote. Opening this link:

https://autoremotejoaomgcd.appspot.com/sendmessage?key=APA91bHfsnJn7b1EgvnoROOPLBUiy4aIFMxPkF9shm7Z-XUfG7dxBfUR4CGc1K2NYl73FjvCB9OitNRHwUbG0xz17yq8LZa09rBrXcoqDKdLM-fIf8W97d6JbdnJxyvNYlWUZvhqzmsDMWPLqk6KBqyPfy6NRIy8AVYXkB4xQJ0eiAaF6m2FkGI&message=Forward

will make my Phone say "forward". I will have 4 buttons, forward, left, right, back. Its for a simple school project where a person wearing a blind fold will be controlled by my phone saying directions.

I need a button that will open that url but not go to the site or leave my site. Is this posable?

Upvotes: 1

Views: 78

Answers (1)

Mark Ormesher
Mark Ormesher

Reputation: 2408

You could use JavaScript to send an AJAX request in the background to that page.

In your HTML you could have something like this:

<input type="button" value="Forward" class="movement-btn-f" /><br />
<input type="button" value="Back" class="movement-btn-b" /><br />
<input type="button" value="Left" class="movement-btn-l" /><br />
<input type="button" value="Right" class="movement-btn-r" />

Then in your JavaScript, something like this:

$(document).ready(function() {

    $('.movement-btn-f').click(function() {
        $.get("your forward URL here");
    });

    $('.movement-btn-b').click(function() {
        $.get("your back URL here");
    });

    // etc...

});

To use that you'd need to include the jQuery library (see: http://www.jquery.com).

You might want to check out the documentation (http://api.jquery.com/jquery.get/) and see how you could use the success callback to wait for a command to be sent and block others in the meantime, but that depends on your application.

Upvotes: 1

Related Questions