Results 1 to 4 of 4

Thread: Remove parameter from URL without refreshing

  1. #1
    Join Date
    Jun 2008
    Posts
    192
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Remove parameter from URL without refreshing

    I need a way to remove parameters from the URL without refreshing the page. The only way I know of to change the URL is by saying:

    window.location.href = ...

    But this refreshes the page.

    I also tried this:

    window.history.replaceState({}, "", window.location.href.substring(0, position_of_parameter_to_remove));

    but this also seems to refresh the page.

    The reason I need to remove the parameter from the URL is as follows: I have two buttons on the page. One of them adds the parameter to the URL and reloads the page with it. When the page reloads, I use that parameter. The second button also reloads the page, but in this case, I want the parameter not to be there so that it doesn't get used when the page reloads. However, I have no control over this button (it's in a special "captivate" object that I have no access to). So I cannot tell it to reload the page with a URL that doesn't have the parameter. It just reloads the page "as is". So I'm trying to remove the parameter as soon as it gets retrieved and used. That way, the parameter will only exist in the URL when the first button is clicked and the page reloads.

    But I still don't know how to do that without doing another page reload. Can anyone help me?

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I can't make any firm suggestions without seeing your page, but in a case like this, I would try to concentrate on the factors that you are able to influence - in other words, can you rewrite the first button's function so that it doesn't set parameters in the URL?

    For more specific help, please provide a link to your page or a simplified example in JSFiddle.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    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

    I would add:

    I don't believe you can change (in real time - you can rewrite it so that the server will see and/or display it differently, and that might or might not satisfy your requirements - javascript cannot do this though, it must be done on the server side with .htaccess or some sort of configuration change) the url without reloading the page. They sort of define each other. The one exception is the hash (#) if that's what you mean, you can tell the browser to change that via javascript:

    Code:
    location.hash = '';
    Modern browsers will not reload. This will change the hash from something like:

    #top

    to either nothing or to just a # with nothing after it, depending upon the browser.

    Hashes can be complex and can look a lot like query strings and might be called parameters. If that's what you have, you can rewrite using javascript, otherwise you will have to edit the script that you seem to say you have no access to, or do something that may or may not work on the server side - assuming you have access to that part of your host's configuration.

    Another option would be to do whatever it is you want to do in a different way that doesn't involve this problem.

    If you don't know if you have a hash or not, we would need to see the page. If you don't have a hash, seeing the page might still reveal a workable approach.
    - John
    ________________________

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

  4. #4
    Join Date
    Jun 2008
    Posts
    192
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    Thanks everyone for your help.

Similar Threads

  1. Resolved JS OOP method with parameter??
    By XManBG in forum JavaScript
    Replies: 2
    Last Post: 11-17-2013, 02:30 PM
  2. What is the 3rd parameter?
    By kuau in forum PHP
    Replies: 2
    Last Post: 11-08-2008, 12:08 AM
  3. Using the REV parameter?
    By yabot in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 03-12-2008, 10:31 PM
  4. Using a function as a parameter of another one
    By ellyz in forum JavaScript
    Replies: 3
    Last Post: 12-27-2005, 10:20 PM
  5. Using a function as a parameter of another one
    By ellyz in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 12-27-2005, 11:34 AM

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
  •