My site uses URL's with urlencoded JSON in them e.g:
domain.com/search.php?q=boat&rank=high&bq={"category"%3A["Sail+Boats"]%2C"boat_country"%3A["CA"]}
So just the JSON bit is urlencoded when I create the URL's. When I read this using $_GET I urldecode and json_decode $_GET['bq'] to get a normal JSON object.
I now wish to add this full querystring as a hash to the end of another URL so I can easily implement a 'back to search' link on this second page. e.g:
domain.com/ben.html#q=boat&rank=high&bq={"category"%3A["Sail+Boats"]%2C"boat_country"%3A["CA"]}
As I can't get the hash value using PHP, I have tried to use Javascript (using JQuery) like so:
if(window.location.hash) {
var hash = window.location.hash.substring(1); //Puts hash in variable, and removes the # character
$('#boat_page_breadcrumb').html('<li><a href="/search.php?'+hash+'">‹ Back to search results</a></li>');
}
The link this produces does not work. I tried using urlencode in PHP which produces this:
ben.html#rank%3Draw_gbp_price%26bq%3D%257B%2522category%2522%253A%255B%2522Sail%2BBoats%2522%255D%252C%2522boat_country%2522%253A%255B%2522CA%2522%255D%257D
The link that is then produced by the JS (below) works fine in FF but not in Chrome or Safari - i.e. the PHP cannot interpret it using normal $_GET.
/search.php?rank=raw_gbp_price&bq=%7B%22category%22%3A%5B%22Sail+Boats%22%5D%2C%22boat_country%22%3A%5B%22CA%22%5D%7D
How can I safely pass the original working URL between pages?