2

I have a file that sends an email to my gmail account with a Link, i want that on clicking of that link i should be able to open the result url in new window (not in new tab).

I have tried the following code with javascript but it does not works well. It does not create's link also, please can any one tell me where i am going wrong:

$links ='<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">function open_mywindow(http_url){ win = window.open(http_url,"win","height=600,width=600,scrollbars=1,resizable=1,help=0"); win.focus();}</SCRIPT><a href="javascript:open_mywindow('http//www.google.com')">open</a>';

Please Help me out in this.

Code snippet will be much appreciated.

iPhnQ
  • 501
  • 8
  • 19
  • http://www.w3schools.com/jsref/met_win_open.asp - name should be "_blank" for new window – x29a Sep 09 '13 at 11:48
  • @x29a have you tried link you posted? – Dexa Sep 09 '13 at 11:49
  • 1
    @Dexa yes, the link works and i get to the docs of "window.open()". Of course if email clients (as stated in other answers) dont execute JS, you are lost anyway. – x29a Sep 09 '13 at 11:56
  • yes so i think google will not let me do this :P – iPhnQ Sep 09 '13 at 12:00
  • @x29a My bad, I've tried first example, didn't see second. Yes I agree changes are lost in case of email clients. – Dexa Sep 09 '13 at 12:01

3 Answers3

4

You can't:

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Worth mentioning: Even if you provide `_blank` value for `target` attribute, web-mail clients may override this. (_blank is probably auto-defined even if target is not set.) – Daniel Sep 09 '13 at 11:49
  • @Quentin So in Short their is no way that i can do this? Right? – iPhnQ Sep 09 '13 at 11:58
1

Any popular Email Client like Gmail won't allow you to run the javascript code. You can however use the code <a href="#anchorname" target="_blank">...</a>

koolnyze
  • 23
  • 3
0

You are breaking your string at ...dow('http//www.google.com')">o...

Should be

$links ='<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">function open_mywindow(http_url){ win = window.open(http_url,"win","height=600,width=600,scrollbars=1,resizable=1,help=0"); win.focus();}</SCRIPT><a href="javascript:open_mywindow(\'http://www.google.com\')">open</a>';

(note the \' in url, to escape single quote which you used for php string enclousure)

You are also missing a semicolon after http in link.

David Pucko
  • 81
  • 1
  • 4