Home » Opening PayPal in a new window

Opening PayPal in a new window

Monday, May 12th, 2008 at 5:35pm in Development Blog

A couple of users have asked how to have the PayPal button open a new window instead of opening in the same one.  It’s fairly easy with a little bit of JavaScript.

Open the thanks.tpl file from whatever theme you’re using.  Look for a line with <!–paypalbutton–> in it.  Below that line add the following.

 

<script type="text/javascript">
for (var i=0; i<document.forms.length; i++)
    {
    if (document.forms[i].action.match(/paypal\.com/))
        {
        document.forms[i].target = "_blank";
        }
    }
</script>

 

What this does is loop through any forms (the PayPal link is an HTML form with several hidden fields and one graphic submit button) on the page and if they are submitting to paypal.com the target is changed to _blank which makes the link open a new page.  Any other forms (search boxes, email subscription fields, etc) will not be affected.

Why?

So, why do you need this?  The user that first asked was running ProofBuddy inside a frameset on their site.  For some reason PayPal has issues with this and throws a very nondescript error when you try to access from a framed page.  She needed a way to break out of the frameset.

Some people also just like the idea of opening PayPal in a separate window so that their site is still open.

Comments

Leave a Reply