Jump to content

[SOLVED] Converting HTML to PHP echo breaks code.


ScopeXL

Recommended Posts

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.

<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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.