0

I am new to PHP and trying to open multiple pages from a single link, such as https://www.google.co.uk, https://www.youtube.com and https://www.stackoverflow.com/ by using code from this answer.

echo "<a href='https://www.google.co.uk' onclick=
window.open('https://www.youtube.com');
window.open('https://www.stackoverflow.com/');
return true;>multiopen</a>"; 

When running my code only the first two links, https://www.google.co.uk and https://www.youtube.com, open. the third link, https://www.stackoverflow.com/, does not.

I found this example to execute multiple functions from one single attribute but I cannot seem to replicate the syntax in PHP. Any help would be much appreciated.

Jsk
  • 159
  • 1
  • 13

1 Answers1

1

you can try the anonymous function:

echo "<a href='https://www.google.co.uk' onclick=\"function(){
           window.open('https://www.youtube.com');
           window.open('https://www.stackoverflow.com/');
           return true;
   }\">multiopen</a>";
wanjaswilly
  • 314
  • 2
  • 11
  • When trying the above code I get a syntax error, perhaps due to the use of " instead of ' before function and after the close brace? When I make these changes I no longer get a syntax error but the code does not work as intended. – Jsk May 26 '20 at 10:41
  • i have escaped the double quotes, try now – wanjaswilly May 26 '20 at 10:47
  • This solved the syntax error but only the first link opens. – Jsk May 26 '20 at 11:02
  • and isnt the broeser blocking the other window??? on my side firefox prevents that – wanjaswilly May 26 '20 at 11:08
  • As I mentioned in my question, the first two links open as intended in my original code. – Jsk May 26 '20 at 11:11
  • It turns out that the multiple browsers I tried only allowed for one 'pop-up' so disabling this was required. Also my initial code required the additional quotes which I was able to deduce from your answer and therefore I have accepted this as the answer. – Jsk May 26 '20 at 13:20