I have a webpage that has several links that link to the same page, but depending on the link the user clicks I need to pass different info to that other page. I know how to do this in PHP through the URL and using $_GET[] but I am unsure how to do it using only javascript/jquery and html. Any idea? Thanks.
1 Answer
You can attach a query string to the link, just as you would to use $_GET with PHP, but retrieve the query string on the target page using JavaScript, as explained here: How can I get query string values in JavaScript?
Edit: I've looked some more at the page to which I linked. There's a lot of very general code there, but if you use an = sign and only one parameter, you can split off the parameter with a JavaScript split:
<a href="target.html?from=A">Came from A</a>
target.html's 'location.search' will contain "?from=A" and a simple split will do it.
1 Comment
Bob Brown
Also, note that this approach does not require JavaScript on the sending page, only on the target page. (If you have JavaScript on the sending page anyway, well, that's a horse of a different color.)
#!) to store data, but that's a little sketchy.