Need to Open Two URL while clicking product view page button in grid mode, Basically its a coupon site. In Grid mode when clicking the product view page button. It has to open product page url & coupon site url. Am facing an error. When clicking the button, It opens the product page of last product in the grid view.

The Code i used is`

<p><button type="button" title="<?php echo $buttonTitle ?>" id="product-addtocart-button" class="button btn-cart" 
                        onclick="openWindow()"><span><span><?php echo $_product->getCouponCodeUse(); ?></span></span></button></p>

                        <script type="text/javascript">
function openWindow() {
var popup = window.open("<?php echo $_product->getCouponUrlValue() ?>","_self");
            window.open("<?php echo $_product->getProductUrl() ?>","window1");


1.) Next to each button you redefine the function "openWindow" (in the global namespace). You could use a different name each time, or better, use Event.observe() instead of "onclick".

2.) You should probably open the popup in window1 before opening a new page in the same window (_self), this seems to stop the JS processing immediately.

  • hi fschmengler, Thanks for your reply, Am totally new to magento and not good in js. Can you please explain me in detail. – sakthibalan Aug 26 '15 at 11:24
  • This is not really a Magento specific problem. Check out the linked documentation of Event.observe and try to write a "click" observer for each button (by the way, you must use a different id attribute for the button each time). Come back, when you tried it and are struggling with specific code that you have written. – Fabian Schmengler Aug 26 '15 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.