hide variables passed in URL

后端 未结 4 1097
情深已故
情深已故 2021-01-05 05:12

We\'ve been working on a web application and we\'ve just about got it finished up, but there\'s one thing that bothering us (although by no means is it going to stop product

相关标签:
4条回答
  • 2021-01-05 05:30

    You could post the data, then let the server include the posted data in the page, e.g.:

    echo "<script> post_data = ".json_encode($_POST)." </script>";
    

    This works cross-browser.

    0 讨论(0)
  • 2021-01-05 05:34

    It's possible to rewrite the URL using JavaScript's history API. History.js is a library that does this very well.

    That being said, I don't think there's any need for removing the query-string from the URL, unless you're dynamically changing the contents of the page to make the current query-string irrelevant.

    0 讨论(0)
  • 2021-01-05 05:43

    Your question seems to indicate that the target page is not and will not be powered by some server-side script. If that's the case, I'd suggest changing the querystring to a hash, which has the advantage of being directly editable without triggering a page-load:

    http://yourdomain.com/page.html#search=value

    <script type='text/javascript'>
      // grab the raw "querystring"
      var query = document.location.hash.substring(1);
    
      // immediately change the hash
      document.location.hash = '';
    
      // parse it in some reasonable manner ... 
      var params = {};
      var parts = query.split(/&/);
      for (var i in parts) {
        var t = part[i].split(/=/);
        params[decodeURIComponent(t[0])] = decodeURIComponent(t[1]);
      }
    
      // and do whatever you need to with the parsed params
      doSearch(params.search);
    </script>
    

    Though, it would be better to get some server-side scripting involved here.

    0 讨论(0)
  • 2021-01-05 05:43

    You can use the History API, but it does require a modern browser

    history.replaceState({}, null, "/index.html");
    

    That will cause your URL to appear as /index.html without reloading the page

    More information here:

    Manipulated the browser history

    0 讨论(0)
提交回复
热议问题