1

So I was wondering how I can code a button to open 2 url's. I have seen retailmenot.com do it when clicking on the button "Get Deal". It opens a new tab with the their article inside their own website but on the original tab it's open a link to the deal site. eg. click on "Get Deal" here http://www.retailmenot.com/view/bestbuy.com

So my code I have done is

<!-- Author -->         
<span class="mix-author"></span>   
    <a attr="<?php echo $item->author_email; ?>" href="<?php echo $website_url; ?>" target="_blank" style="background-color: grey;padding: 5px 7px;border-bottom: 4px ;border-radius: 4px;float: right;color: white;" >GET DEAL</a> 
<?php } ?>

The above code opens in a new tab. but I want it to open in the current tab while I want the code(link) below to open in the new tab without showing me the title when the above "GET DEAL" is clicked.

<?php if ($params->get('show_title')) { ?>
    <!-- Title -->
    <h3>
        <a href="<?php echo $item->link; ?>" class="mix-title"><?php echo $item->main_title; ?></a> 
    </h3>
<?php } ?>

Please help me out.

James Zaghini
  • 3,895
  • 4
  • 45
  • 61
Samantha
  • 13
  • 4

1 Answers1

0

I think you need to write a javascript function that does both and gets called on the button click:

function twoLinks(same_page_url, new_window_url)
{
    window.location = same_page_url; // this will open in the current window
    window.open(new_window_url); // this will open in a new window
}

and then call it like so from your link:

<a attr="<?php echo $item->author_email; ?>" href="javascript:void(0);" onclick="twoLinks('<?php echo $website_url; ?>', '<?php echo $new_window_url; ?>');" style="background-color: grey;padding: 5px 7px;border-bottom: 4px ;border-radius: 4px;float: right;color: white;" >GET DEAL</a> 

I borrowed from this answer for part of mine:
jQuery: go to URL with target="_blank"

Regarding your further comments, everything works for me as expected when I try your code. Inspect the html in the browser, and your GET DEAL link should contain something like:

<a attr="" href="javascript:void(0);" onclick="twoLinks('http://www.arg.is', 'http://www.google.com');" style="background-color: grey;padding: 5px 7px;border-bottom: 4px ;border-radius: 4px;float: right;color: white;">GET DEAL</a> 

I need to see error messages and/or the rendered html of your link to help you. I'm thinking either:

  1. You aren't included the http:// part like I have, and your link is trying a relative path that doesn't exist on your server
  2. One of your variables you're printing into the function parameters isn't what it should be
Community
  • 1
  • 1
Chris Trudeau
  • 1,427
  • 3
  • 16
  • 20
  • Thank you, Thank you, thank you so much. It worked ! I added the extra " after attr= and when i checked for errors it showed me open.js not found. Since I am using joomla, the file they were looking for was in the first root folder of the site, (www.website.com/open.js). I moved the file there and now it's working perfect. Thank you so much. Love you guys.......Yeah I'm happy. – Samantha Dec 18 '15 at 14:30