Results 1 to 2 of 2

Thread: Java pop-up window

  1. #1
    Join Date
    Sep 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java pop-up window

    I'm not really good with javascript and need help with a problem. I'm creating a pop-up window that goes to another site but sends the url it's coming from in the url it's going to.

    Ok here's what I have if that's confusing.
    Code:
    <head>
    <script type="text/javascript">
    function popupwin(url) 
    {
     var width  = 650;
     var height = 250;
     var left   = (screen.width  - width)/2;
     var top    = (screen.height - height)/2;
     var params = 'width='+width+', height='+height;
     params += ', top='+top+', left='+left;
     params += ', scrollbars=1';
     newwin=window.open(url,'popupwin', params);
     if (window.focus) {newwin.focus()}
     return false;
    }
    </script>
    </head>
    <body>
    <a href="javascript: void(0)" onClick="popupwin('http://example.com/check.php?id=http://$_SERVER[SERVER_NAME]$_SERVER[REQUEST_URI]'); return false;">Centered popup window</a>
    </body>
    Now that above code works fine in most cases and on most sites. The problem is that one forum I've tried it on has a seo mod which means the php comand $_SERVER[REQUEST_URI] isn't the same that's in the address bar. Instead of showing
    Code:
    http://sitename.com/forum/main-forum/1-test-post-title-some-list.html
    it's showing
    Code:
    http://sitename.com/forum/showthread.php?p=1
    After Googling I know that document.write(location.href) will give me the exact url of the seo url as it appears in the address bar which is what I want. Can anyone show me how to combine document.write(location.href) with my code. I know it's probably easy for most but I only really know basic html and php and I'm only new to javascript.

    Thanks in advance.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The document.write() method should be avoided in most cases, all really after page load, as at that point it will overwrite the page.

    Also, location.href will not give you anything other than what appears in the address bar.

    Anyways, I'm not sure exactly what you are going for, but here's what I would try:

    Code:
    <a href="javascript: void(0)" onclick="popupwin('http://example.com/check.php?id=' + encodeURIComponent(location.href)); return false;">Centered popup window</a>
    I use the encodeURIComponent() method to avoid messiness/errors that can occur if a URL with its own query component is used as a part of a query in another URL. If you need this information decoded on the other end (in this case at 'example.com'), you may use the decodeURIComponent() method at the receiving end there to get it to look like it did in the address bar.
    Last edited by jscheuer1; 09-27-2009 at 02:41 PM. Reason: minor syntax change
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •