Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.