SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Location.href within onClick event

    Hi....

    I am creating a send to a friend link on my site. The link will open a pop up window, which contains a form.

    I have a function that opens the centered pop up window, and it is called like so (the function declaration resides in an external script):
    Code:
       onClick="newWindow('http://www.mysite.com/send.php','','300','500','')"
    I now need to append the current page's URL to the end of the URL ike so:
    Code:
       onClick="newWindow('http://www.mysite.com/send.php?page=xxx','','300','500','')"
    This is sso that I can then use PHP in the pop up toget the variable from the query string.

    I know that I can use location.href to get the current page url, but am not sure how I would include it in the onClick.

    I have tried the following:

    Code:
      onClick="newWindow('http://www.mysite.com/send.php?page=location.href','','300','500','')"
    but that doenst work...

    Has anybody got any ideas?

    D

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
      onClick="newWindow('http://www.mysite.com/send.php?page="+window.location.href+"','','300','500','')"
    cheers

  3. #3
    SitePoint Guru Dashman's Avatar
    Join Date
    Jan 2006
    Location
    Manchester, UK
    Posts
    627
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi, thanks for that, but it does not appear to be working....

    the full link is as follows:
    HTML Code:
    <a href="#" onClick="newWindow('http://www.mysite.com/send.php?page="+window.location.href+"','','300','500','')">Send</a>
    Is this right? ie: should window.location.href be able to site by iteslef in the middle of the html like that?

    When I view the browser source code, window.location.href is written out as is....

    Does that make sense?

    D

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
     <a href="#" onClick="newWindow('http://www.mysite.com/send.php?page='+window.location.href,'','300','500','')">Send</a>



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
  •