SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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 { ?>
    Animated Chatrooms - www.121chatrooms.net

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Hi,

    You could use location.href.

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

    PHP Code:
    <?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:

    HTML Code:
    <!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>

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,812
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    escape() is long dead in JavaScript - it was replaced by encodeURI() and encodeURIComponent() over a decade ago.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just tried your code but when I click link it seems to direct back to the same page.
    Animated Chatrooms - www.121chatrooms.net

  5. #5
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,938
    Mentioned
    214 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by Mike4x4s View Post
    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?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •