0

i'm using this little bit of code to add a 'pin it' button to my wordpress site. I added in target= "_blank" and it still opens in same window.

<a target="_blank" href='javascript:void((function()%7Bvar%20e=document.createElement(&apos;script&apos;);e.setAttribute(&apos;type&apos;,&apos;text/javascript&apos;);e.setAttribute(&apos;charset&apos;,&apos;UTF-8&apos;);e.setAttribute(&apos;src&apos;,&apos;//assets.pinterest.com/js/pinmarklet.js?r=&apos;+Math.random()*99999999);document.body.appendChild(e)%7D)());'>Pin it</a>
Jordan
  • 237
  • 7
  • 21

2 Answers2

1

Pinterest have a button generator which is probably the easiest and recommended way to do this. But if you're much more inclined to do this via link you can try this..

<a href="http://pinterest.com/pin/create/link/?url=[yourURLHere]" onclick="javascript:window.open(this.href,
  '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;">Pin it</a>

Refer to this question for more info.
By the way, you might want to read this documentation, just to be aware of possible consequences if you go this route.

Community
  • 1
  • 1
HCN
  • 111
  • 1
  • 9
0

Here's another option you can try. Bear in mind that this requires JQuery. So make sure that it's included on your page like so:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

here is your solution:

<a href="http://example.com" rel="external">External link</a>
<script type="text/javascript">
    $('a[rel="external"]').attr('target', '_blank');
</script>

Notice the rel="external" that was added to the link

user2993497
  • 525
  • 1
  • 7
  • 21