1

I want to create elements which (when clicked) will guide visitors towards two differenct websites (both in new windows). How can I do this? Below are the two ways which I tried, which both do not work as only one page/ window is opened. Thanks in advance!

Timo

  1. The solution as suggested here: How to make a link open multiple pages when clicked . But maybe the solution is outdated, but for me only the first webpage is openend (with all the indicated solutions. (for example the code which is suggested there)

    HTML <a href="#" class="yourlink">Click Here</a>

    $('a.yourlink').click(function(e) { e.preventDefault(); window.open('https://www.youtube.com/watch?v=H9XIXFwpyEc'); window.open('https://stackoverflow.com/search?q=open+multiple+pages'); });

  2. While both using a class and an id with both a different a href and both with the extra options of opening new window also does not work as it only opens the first window

    HTML <a href="#" class="yourlink" id="extra">Click Here</a>

$('.yourlink').html('<a href="url"></a>'); // Add page $('.yourlink a').attr('target', '_blank');// Make sure it opens in new window

$('#extra').html('<a href="url"></a>'); // Add page $('#extra a').attr('target', '_blank');// Make sure it opens in new window

Community
  • 1
  • 1
TimothyUtrech
  • 77
  • 1
  • 6

1 Answers1

0

Using Chrome, I'm not seeing the problem you describe. But when I tested it in IE, I suddenly got a "popup blocked" message.

It's not strange though. I'd hate it if a single click on a link could suddenly spawn 10 new windows. In this scenario I actually think IE handles it better (by blocking the second window).

The thing is that window.open will only work if the action that invokes it is a trusted event. That usually means a user-initiated event, like click. But what Chrome doesn't account for (I assume) is that a single trusted event can then invoke several window.open.

I've tried to work around this feature, but have not (yet) been able to fool IE. The options, as I see it, are:

  • Ask users to add your site to the popup exceptions (internet settings).
  • Spawn the pages in iframes within your own site
  • Ask users to use another browser ;)

Or the obvious:

  • Use separate links for the windows
Mackan
  • 6,200
  • 2
  • 25
  • 45
  • Thanks Mackan, the last options was my workaround option, so I am going to stick with that. Thanks for your helpt and the clear answer. It is not the solution which I hoped, but it is not a deal breaker. Thanks! – TimothyUtrech May 17 '15 at 10:41