0

When I search for an hotel on tripadvisor, for example here, when I entermy check-in and check-out date, and choose one of the booking sites recommended on the page, I'll go to that booking site, for example this one.

I can see that the checkin and checkout date are included in the URL already: checkin=2013-08-30;checkout=2013-08-31. How was this accomplished? Please note that I only have control to the second website here. I don't have access to the first website.

Thank you!

user2502206
  • 49
  • 1
  • 1
  • 6
  • 2
    [HTML forms - the basics](http://www.w3.org/wiki/HTML_forms_-_the_basics). Or Ajax. – bfavaretto Aug 26 '13 at 20:26
  • Actually, forget ajax. If you're using ajax, you'll need the [history api](https://developer.mozilla.org/en-US/docs/Web/Guide/DOM/Manipulating_the_browser_history) for this. – bfavaretto Aug 26 '13 at 20:34
  • Sorry Guys I don't quite understand... If I only have control to the 2nd website, how can I still get the information filled out on the first website? – user2502206 Aug 26 '13 at 20:47
  • You didn't say there were two separate websites... So the first website is just redirecting to an URL (that lives on the 2nd) that already includes the parameters. What are you asking then? How to read the parameters from your side, considering they're already being passed by someone? Usually that's done server-side, but you can read with js too, see http://stackoverflow.com/questions/1403888/get-url-parameter-with-javascript-or-jquery – bfavaretto Aug 26 '13 at 20:51
  • Based on only having control of the 2nd site, it sounds like the question should be "How to retrieve information passed from one web page through the url" – Chris Rockwell Aug 26 '13 at 20:51
  • Thank you Bfavaretto! I was just not sure if the 2nd site needs to rely on the 1st site to populate parameters in the redirect URL, or there is a way for the 2nd site to retrieve the parameters by itself. So it sound like that the 1st site is responsible for passing along the parameters. Without it's help, I (2nd site) won't be able to accomplish this myself. Thank you! – user2502206 Aug 27 '13 at 12:35

2 Answers2

0

You can set the location in javascript using window.location.href. If you change anything to the left of the #, the browser will attempt to get a new page.

fred02138
  • 3,323
  • 1
  • 14
  • 17
0

Take a look at the URLON library. Then use the URLON.stringify() method to convert your objects to a friendly string that you can set as your hash in the URL via the window.location.hash. You can then convert the query string in your hash back to an object using the URLON.parse() method.

Suvi Vignarajah
  • 5,758
  • 27
  • 38