Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Aug 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    window.location (refresh to anchor)

    Hello,

    I have a dynamically generated web page with a link that a user can click to set a cookie.

    The javascipt that sets the cookie uses the following to refresh the page.

    window.location = window.location;


    I would like to reload the page to an anchor (#chart). As the page is dynamically generated I don't know the exact URL.

    I've tried various methods e.g. below, but with no success.

    window.location = window.location.+"#chart";

    Any suggestions?

    P.S. I know I can replace
    window.location = window.location; with window.location.reload();

  • #2
    Regular Coder
    Join Date
    Jun 2007
    Location
    USA
    Posts
    527
    Thanks
    26
    Thanked 74 Times in 72 Posts
    Quote Originally Posted by rockdoc View Post
    window.location = window.location.+"#chart";
    You have an extra dot there (highlighted). If removing that doesn't fix the problem, try a mix and match of window.location.href
    Trinithis

  • #3
    New Coder
    Join Date
    Aug 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Removed the dot but still no luck (neither refreshing or going to the anchor).

    Have even tried your suggestion

    window.location.href+"#chart";

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Hi rockdoc,
    It should be window.location.hash="#chart";
    See if it helps

  • #5
    New Coder
    Join Date
    Aug 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    rangana,
    Ive tried your suggestion also, but still no luck ...

    window.location = window.location.hash="#chart"; //will not refresh to an anchor

  • #6
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    When do you want this to achieve??...
    using window.location = window.location.has="#chart"; has an effect, apparently, it fails because it opens a new location of the window

  • #7
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    I am going to sleep few minutes from now, you could also give this code a try:
    Code:
    function anchor()
    {
    var url='anchor.htm'; //name of your URL here
    location = url +"#chart";
    }
    I tested it on my PC and it worked!..See if it helps


  •  

    Posting Permissions

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