0

I have the following link that when clicked, opens a new tab and refreshes the page with the link in. It works fine in Safari and Chrome but opens duplicate tabs in Firefox.

<a href="../print_letters/letter.php" class="button success" target="_blank" onClick="openWindowReload(this)">Run Letters</a>

function openWindowReload(link) {
var href = link.href;
window.open(href,'_blank');
location.href = 'index.php' + "?welcome_letters=export&welcome_letters=export"
}

Any ideas why Firefox is doing this and how to resolve it?

j08691
  • 204,283
  • 31
  • 260
  • 272
John Higgins
  • 857
  • 12
  • 25

1 Answers1

0

I think it's because you don't stop the default behavior. Could you call preventDefault on the click event?

farvilain
  • 2,552
  • 2
  • 13
  • 24
  • @ farvilain Can you tell me how I would apply preventDefault to my code please? – John Higgins Nov 18 '19 at 16:29
  • From my understanding, this stops the parent page from refreshing. I need the parent page to refresh. The issue I have is that Firefox opens two tabs instead of just one. Safari and Chrome only open one tab which is correct. – John Higgins Nov 18 '19 at 16:36
  • `return false;` at the end of the function could help. There is a thread about that here https://stackoverflow.com/questions/128923/whats-the-effect-of-adding-return-false-to-a-click-event-listener. If not, I'll try tomorrow with Firefox. not on my personnal laptop right now :( – farvilain Nov 18 '19 at 16:58
  • return false; stopped 2 tabs being opened but unfortunately it also stopped the parent page from being refreshed. – John Higgins Nov 19 '19 at 09:00