Persistent URL query string throughout the entire site?

后端 未结 3 1849
天命终不由人
天命终不由人 2021-01-26 22:34

This is one of those situations where I feel like there is a simple answer right in front of me...hopefully you guys/gals can show me the light.

PROBLEM :

相关标签:
3条回答
  • 2021-01-26 22:46

    So - the answer here was this :

    1. Use JS to grab the query string
    2. Validate the query string
    3. Add to a cookie
    4. Append the cookie'd query string to every href in the DOM

    Like I said...I knew there was a simple example staring me in the face haha!

    0 讨论(0)
  • 2021-01-26 22:59

    This question is old and obviously must have been solved by now by @aepearson. Adding another answer from current day perspective.

    Now, one can also easily use sessionStorage also to save navigation data into a key. Pick it up whenever required, and add to url.

    Example from Mozilla

    // Save data to sessionStorage
    sessionStorage.setItem('key', 'value');
    
    // Get saved data from sessionStorage
    var data = sessionStorage.getItem('key');
    
    // Remove saved data from sessionStorage
    sessionStorage.removeItem('key');
    
    // Remove all saved data from sessionStorage
    sessionStorage.clear();
    
    0 讨论(0)
  • 2021-01-26 23:08

    If you just want to persist this exact query string on each page, why not set the linked pages to insert the string into a session variable. Then on each page link check to see if the session variable exists and add it to the query string when redirecting.

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