0

Is there a way to set GET or POST variables with javascript when the user leaves the page? If not, is there a way to change all links in the page to have GET variables attached? Or perhaps is there a way to change the links with a function when the user clicks them?

Sorry for my brevity, I have found how to get GET variables upon page load with javascript, but I failed to find this information, and could not find this question elsewhere on stackoverflow.

UPDATE:

What we want is that when the user goes to another page on the same website, if the GET variable "foo" is currently set, we want it to remain set on the next page. I've found how to check if the variable is set, but not how to set it again when the user goes elsewhere on the site.

4
  • 1
    What do you mean "when the user leaves the page"? Just create normal links with your querystring parameters. Commented Dec 4, 2013 at 5:12
  • When they go to another page in the same website. Let me update real quick with a little more explanation. Commented Dec 4, 2013 at 5:15
  • Saw your update. Why are you doing this exactly? Seems like you could use PHP session variables to achieve this kind of thing instead. What functionality are you aiming for? Commented Dec 4, 2013 at 5:19
  • I'm working for a company, and my boss doesn't like php -_- we're building a site with a mobile and non-mobile side, and we can detect if the user is on a phone, but if the user is on the phone we want them to be able to use the desktop version still. So we are planning on using get variables, and we can easily set the get variable in the link to the non-mobile/desktop side, and receive the variable there, but I'm not sure how to set the variable again if they decide to continue browsing the non-mobile site, and if the variable isn't set, they just get thrown back to the mobile site. Commented Dec 4, 2013 at 5:31

1 Answer 1

1

I use this to function to replace all user/login links to my desired link on page load.

function (context) {
  $("a[href*='/user/login'], a[href*='?q=user/login']", context).each(function () {
    this.href = this.href.replace(/user\/login/, 'desired link');

can you post some code what you want to implement

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.