Open same window

Just got this code which opens a link in a new window, how can I change it to open in the same window?

function openRoom(roomId, roomName) {

<?php if (isset($_SESSION[‘accountId’]) || isset($_COOKIE[‘accountId’])) { ?>
window.open(‘chatroom.php?join=’+escape(roomName), ‘Room’+roomId, ‘width=1059,height=554,scrollbars=no’).focus();
<?php } else { ?>

Hi,

You could use location.href.

You might need to play about with the exact syntax, but something like this should work:

<?php if (isset($_SESSION['accountId']) || isset($_COOKIE['accountId'])) { ?>
location.href = 'chatroom.php?join=' + escape(roomName) + 'Room' + roomId;	
<?php } else { ?>

A simple example of the syntax would be:

<!DOCTYPE HTML>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>location.href example</title>
  </head>
  <body>
    <script>location.href = 'http://www.sitepoint.com';</script>
  </body>
</html>

escape() is long dead in JavaScript - it was replaced by encodeURI() and encodeURIComponent() over a decade ago.

I just tried your code but when I click link it seems to direct back to the same page.

Let’s try and get it working in JavaScript first, then (without the PHP).
Can you give me an example of what the two parameters (roomName and roomId) should contain.
What should the final url look like?