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’])) { ?>‘chatroom.php?join=’+escape(roomName), ‘Room’+roomId, ‘width=1059,height=554,scrollbars=no’).focus();
<?php } else { ?>


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:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>location.href example</title>
    <script>location.href = '';</script>

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?