ScopeXL Posted July 21, 2009 Share Posted July 21, 2009 Hello, I recently converted an HTML page to PHP so I can show certain text when a user is logged in, and no text when a user is logged out. It seems to transfer fine, but the javascript I was using to resize a link window breaks when its done. Here is the original code HTML based. <head> <script> <!-- function wopen(url, name, w, h) { // Fudge factors for window decoration space. // In my tests these work well on all platforms & browsers. w += 32; h += 96; var win = window.open(url, name, 'width=' + w + ', height=' + h + ', ' + 'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=no, resizable=no'); win.resizeTo(w, h); win.focus(); } // --> </script> </head> <a href="page.html" target="sendtext" onclick="wopen('http://webbot.bnetweb.org/malgasm/sendchat.php', 'popup', 650, 32); return false;"> Click here to talk on the WebBot</a>. (Use password <b>******</b>). Here is the converted code: echo '<script> <!-- function wopen(url, name, w, h) { // Fudge factors for window decoration space. // In my tests these work well on all platforms & browsers. w += 32; h += 96; var win = window.open(url, name, "width=" + w + ", height=" + h + ", " + "location=no, menubar=no, " + "status=no, toolbar=no, scrollbars=no, resizable=no"); win.resizeTo(w, h); win.focus(); } // --> </script> </head>'; if ($context['user']['is_logged']) { echo '<a href="page.html" target="sendtext" onclick="wopen("http://webbot.bnetweb.org/malgasm/sendchat.php", "popup", 650, 32); return false;"> Click here to talk on the WebBot</a>. (Use password <b>*****</b>).'; } else { // Do Nothing... } Everything works, but the original code would open the link in a new, resized window using the javascript, now it will only try to open the page.html and ignore the onClick. Any ideas an how to fix or what I am doing wrong? Thank you in advance. Link to comment https://forums.phpfreaks.com/topic/166737-solved-converting-html-to-php-echo-breaks-code/ Share on other sites More sharing options...
trq Posted July 21, 2009 Share Posted July 21, 2009 echo '<a href="page.html" target="sendtext" onclick="wopen(\'http://webbot.bnetweb.org/malgasm/sendchat.php\', "popup", 650, 32); return false;"> Click here to talk on the WebBot</a>. (Use password <b>*****</b>).'; Link to comment https://forums.phpfreaks.com/topic/166737-solved-converting-html-to-php-echo-breaks-code/#findComment-879234 Share on other sites More sharing options...
ScopeXL Posted July 21, 2009 Author Share Posted July 21, 2009 Still same result, I also attempted adding escape characters to the javascript code itself as well. The page opens "page.html" and ignores the onClick. Link to comment https://forums.phpfreaks.com/topic/166737-solved-converting-html-to-php-echo-breaks-code/#findComment-879240 Share on other sites More sharing options...
Q Posted July 21, 2009 Share Posted July 21, 2009 <script> <!-- function wopen(url, name, w, h) { // Fudge factors for window decoration space. // In my tests these work well on all platforms & browsers. w += 32; h += 96; var win = window.open(url, name, "width=" + w + ", height=" + h + ", " + "location=no, menubar=no, " + "status=no, toolbar=no, scrollbars=no, resizable=no"); win.resizeTo(w, h); win.focus(); } // --> </script> </head> <?php if ($context['user']['is_logged']) { ?> <a href="page.html" target="sendtext" onclick="wopen('http://webbot.bnetweb.org/malgasm/sendchat.php', 'popup', 650, 32); return false;"> Click here to talk on the WebBot</a>. (Use password <b>******</b>). <?php } else { // Do Nothing... } ?> PHP lets you divide your script in to chunks, so that you can just exit php and write normal HTML, without any escapes and other annoying stuff. - The above example is how I would have done it Link to comment https://forums.phpfreaks.com/topic/166737-solved-converting-html-to-php-echo-breaks-code/#findComment-879277 Share on other sites More sharing options...
ScopeXL Posted July 21, 2009 Author Share Posted July 21, 2009 Ah, I was unaware I could end a PHP statement in the middle of an 'if'. This has fixed my problem. Thank you thorpe and Q for making it so this could be resolved quickly. Link to comment https://forums.phpfreaks.com/topic/166737-solved-converting-html-to-php-echo-breaks-code/#findComment-879285 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.