How could I do a redirect to this URL after my user clicks on the button?

I've got a button that my user can click on that opens up a pop up window. You can see the code below. I want to keep track of when that user clicks on the button and I thought I would have a situation where rather than opening up the pop up window right away, I would first direct my user to a page where the database is updated and then redirect it to the original pop up address.

How would I do that?

So here's the code that I have right now:

<a href="#" onclick="FB.ui({method: 'feed',name: 'I just voted!', link: 'https://apps.facebook.com/texaco_songwriting/', picture: 'http://www.countryshowdown.com/songwriting/images/facebook_news_feed.jpg', caption: 'Texaco Country Showdown Songwriting Contest', description: 'I just voted for <?php echo $display_name; ?> on the Texaco Country Showdown Songwriting Contest' }); return false;"><IMG SRC="images/news_feed_button.jpg" border="0"></a>

How could I change that so my user goes to a page where I do my database stuff and then redirect them to the window that you see referenced above?
brucegustPHP DeveloperAsked:
Who is Participating?
 
RoonaanCommented:
An alternative you could use is to just trigger the database seperately from the popup window.

<a href="#" onclick="trackVote(event, this, '<?=htmlspecialchars($display_name);?>');FB.ui({method: 'feed',name: 'I just voted!', link: 'https://apps.facebook.com/texaco_songwriting/', picture: 'http://www.countryshowdown.com/songwriting/images/facebook_news_feed.jpg', caption: 'Texaco Country Showdown Songwriting Contest', description: 'I just voted for <?php echo $display_name; ?> on the Texaco Country Showdown Songwriting Contest' }); return false;"><IMG SRC="images/news_feed_button.jpg" border="0"></a>

Open in new window


Then include a trackVote function:
<script type="text/javascript">
function trackVote(event, link, displayName) {
     var img = document.createElement('img');
           img.style.display = 'none';
           img.src = '/track.php?displayName=' + encodeURIComponent(displayName) + '&random=' + Math.random();
     document.body.appendChild(img);
}

Open in new window


Kind regards,

-r-
0
 
brucegustPHP DeveloperAuthor Commented:
Problem is, I don't have access to the Facebook window itself in that I can't add any script to that part of the challenge. I've got to do my database stuff first, before my user goes to the Facebook interface.

What do you think?
0
 
nap0leonCommented:
I was going to post some code, but it largely mirrors Roonan's approach.

In the onclick of the link on YOUR page, make a call to a page on your site that does the database stuff, THEN call the FaceBook stuff.  Your concern about not having access to FB's site is moot - this is a change to YOUR page.
0
 
brucegustPHP DeveloperAuthor Commented:
Nap0leon, that sounds right. Could you give me an example or point me to an online resource that shows me how to faciliate two actions as far as the onclick that does my database stuff then automatically proceeds to the Facebook dynamic.

I'm not wanting you to do the work for me and I want to learn not just copy and paste, but if you could give me a starting point, that would be just a little bit of awesome.

I appreaciate your time...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.