-3

So I have something that looks like this and I am trying to open a new link with predetermined size/with inside a PHP echo. Here is what I have,

echo '<a href=“noticeboard.php?charid=' .$row_char['noticeID'].'"STYLE="text-decoration: none" target="_blank"> &nbsp;&nbsp; &nbsp;[Announcements]<br>

I have tried :

echo '<a href=“noticeboard.php?charid=' .$row_char['noticeID'].'"" onclick="window.open (this.href, 'child', 'height=400,width=300,scrollbars'); return false">W3C</a> &nbsp;&nbsp; &nbsp;[Announcements]</a>

What am I doing wrong? Is there a easier way to implement this.

Thanks.

vv01f
  • 362
  • 1
  • 4
  • 21
chatslayer
  • 47
  • 3
  • That helps answer the question. Thank-you! I have looked for hours on this. I am new to PHP so trying to learn the basics. – chatslayer May 14 '17 at 05:16
  • No problem. Just a reminder, if if you find answers on Stack Overflow that help, don't forget to upvote, and marked "solved" to whoever best answered your question :) – Jim May 14 '17 at 05:22

2 Answers2

0

As you are not preventing default behavior of tag, you will not be able to execute onclick event of tag :

Try below changes :

echo "<a href=\"noticeboard.php?charid=".$row_char['noticeID']."\" onclick=\"javascript:void(0);window.open (this.href, 'child', 'height=400,width=300,scrollbars'); return false;\">W3C</a> &nbsp;&nbsp; &nbsp;[Announcements]</a>";
Nishesh Pratap Singh
  • 2,131
  • 2
  • 13
  • 20
  • `event.preventDefault();` (first in the block) instead of `void(0);[…]return false;` is the better approach in general and especially when giving an example to beginners. – vv01f May 14 '17 at 05:26
  • Yup, **javascript:void(0)** can be replaced with **event.preventDefault()**, Thanks for pointing that out.. :) – Nishesh Pratap Singh May 14 '17 at 05:29
0

Having a look here, the following should work. Keep in mind the problem was most likely improper escaping so make sure you keep track of opening and closing quotes and not mixing them up.

echo '<a href="noticeboard.php?charid='.$row_char['noticeID'].'" onclick="window.open(\'noticeboard.php?charid='.$row_char['noticeID'].'\', \'child\', \'height=400, width=300, scrollbars\'); return false">W3C</a> &nbsp;&nbsp; &nbsp;[Announcements]';

Jim
  • 587
  • 2
  • 6
  • 19