1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

(location.href) and pop-up window

Discussion in 'JavaScript' started by Mr Happy, Sep 26, 2009.

  1. #1
    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.
    <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>
    Code (markup):
    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
    http://sitename.com/forum/main-forum/1-test-post-title-some-list.html
    Code (markup):
    it's showing
    http://sitename.com/forum/showthread.php?p=1
    Code (markup):
    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.
    SEMrush
     
    Mr Happy, Sep 26, 2009 IP
    SEMrush
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Something like:
    
    <a href="javascript: void(0)" onClick="popupwin('http://example.com/check.php?id=' + location.href + '); return false;">Centered popup window</a>
    
    Code (markup):
     
    camjohnson95, Sep 27, 2009 IP
  3. MaceWin

    MaceWin Peon

    Messages:
    38
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <a href="javascript: void(0)" onClick="popupwin('http://example.com/check.php?id=' +encodeURIComponent(document.location.href)); return false;">Centered popup window</a>
    Code (markup):
    Best to encode the href before sending it to your page.
     
    MaceWin, Sep 27, 2009 IP
  4. Mr Happy

    Mr Happy Greenhorn

    Messages:
    48
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    20
    #4
    thanks very much guy's. Didn't realise it was so easy.
     
    Mr Happy, Oct 5, 2009 IP