How to keep query string parameters as user navigates through the websiteQuery string of referrer URLFind clickable elementsHow to check empty/undefined/null string in JavaScript?How can I convert a string to boolean in JavaScript?How to check if a string “StartsWith” another string?How do I loop through or enumerate a JavaScript object?How can I get query string values in JavaScript?How to loop through a plain JavaScript object with the objects as members?How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I check if a string contains a specific word?
Is this toilet slogan correct usage of the English language?
Start making guitar arrangements
Is the U.S. Code copyrighted by the Government?
Loading commands from file
Is there any references on the tensor product of presentable (1-)categories?
What is this called? Old film camera viewer?
How can "mimic phobia" be cured or prevented?
Is it better practice to read straight from sheet music rather than memorize it?
The IT department bottlenecks progress. How should I handle this?
Can I sign legal documents with a smiley face?
Added a new user on Ubuntu, set password not working?
How should I respond when I lied about my education and the company finds out through background check?
What is this cable/device?
Offered money to buy a house, seller is asking for more to cover gap between their listing and mortgage owed
Which one is correct as adjective “protruding” or “protruded”?
Melting point of aspirin, contradicting sources
When were female captains banned from Starfleet?
Lowest total scrabble score
Are the IPv6 address space and IPv4 address space completely disjoint?
What was this official D&D 3.5e Lovecraft-flavored rulebook?
250 Floor Tower
What was the exact wording from Ivanhoe of this advice on how to free yourself from slavery?
2.8 Why are collections grayed out? How can I open them?
Why did the EU agree to delay the Brexit deadline?
How to keep query string parameters as user navigates through the website
Query string of referrer URLFind clickable elementsHow to check empty/undefined/null string in JavaScript?How can I convert a string to boolean in JavaScript?How to check if a string “StartsWith” another string?How do I loop through or enumerate a JavaScript object?How can I get query string values in JavaScript?How to loop through a plain JavaScript object with the objects as members?How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I check if a string contains a specific word?
I have a situation where I want to preserve a query string between clicks on my Wordpress website.
E.g.
www.mywebsite.com/?utm_source=mysource
When navigating from this link to another page of the website that query string should persist.
E.g.
www.mywebsite.com/anotherpage/?utm_source=mysource
So I decided one easy way to do this would be to modify the javascript so that my function is fired when a click on an anchor tag occurs.
//Ensures that the query string persists between clicks on the site
$("a").on("click", function (event)
event.preventDefault();
window.location.href = event.currentTarget.href + window.location.search;
);
However this doesn't work for other elements on the page like buttons which are not anchor tags but still contain hrefs that modifiy the window location when they are clicked. For example in the php scripts of the theme there is code such as:
<button onClick="location.href=www.anotherwebsite.com"</button>
I could implement another function that implements the same behavior for button elements but I am concerned that whenever another element is added I will have to check for a new type. Is there a better way to ensure that whenever the window location is changed my query string persists?
FYI: I am not allowed to put the information in a cookie which is another way I thought of keeping track of the parameters.
javascript php jquery wordpress
|
show 3 more comments
I have a situation where I want to preserve a query string between clicks on my Wordpress website.
E.g.
www.mywebsite.com/?utm_source=mysource
When navigating from this link to another page of the website that query string should persist.
E.g.
www.mywebsite.com/anotherpage/?utm_source=mysource
So I decided one easy way to do this would be to modify the javascript so that my function is fired when a click on an anchor tag occurs.
//Ensures that the query string persists between clicks on the site
$("a").on("click", function (event)
event.preventDefault();
window.location.href = event.currentTarget.href + window.location.search;
);
However this doesn't work for other elements on the page like buttons which are not anchor tags but still contain hrefs that modifiy the window location when they are clicked. For example in the php scripts of the theme there is code such as:
<button onClick="location.href=www.anotherwebsite.com"</button>
I could implement another function that implements the same behavior for button elements but I am concerned that whenever another element is added I will have to check for a new type. Is there a better way to ensure that whenever the window location is changed my query string persists?
FYI: I am not allowed to put the information in a cookie which is another way I thought of keeping track of the parameters.
javascript php jquery wordpress
Possible duplicate of Query string of referrer URL
– Steven Stark
Mar 8 at 4:30
The above doesn't solve my problem very eloquently as I would have to add the $referrer = $_SERVER['HTTP_REFERER']; to every script where the user is directed to a new link, if I had many pages in my website that could involve modifying a lot of code and writing a lot of duplicate code
– AdaRaider
Mar 8 at 4:37
that's only one of 3 answers though.
– Steven Stark
Mar 8 at 4:38
why not use sessions?
– tim
Mar 8 at 4:40
1
I found some older questions that suggest trying to intercept the location change using a beforeunload handler, but I am not too sure how reliably that would work. And there isn’t much else you could use to intercept just any arbitrary navigation event - history changes fire only when navigation happens via the browser history UI, but not for normal link or button clicks. // Seems a bit counter-intuitive that you want to not only track my initial visit to your page, but to keep sniffing after my a** as I navigate further through the site … but then have that requirement to not use cookies …?
– 04FS
Mar 8 at 8:52
|
show 3 more comments
I have a situation where I want to preserve a query string between clicks on my Wordpress website.
E.g.
www.mywebsite.com/?utm_source=mysource
When navigating from this link to another page of the website that query string should persist.
E.g.
www.mywebsite.com/anotherpage/?utm_source=mysource
So I decided one easy way to do this would be to modify the javascript so that my function is fired when a click on an anchor tag occurs.
//Ensures that the query string persists between clicks on the site
$("a").on("click", function (event)
event.preventDefault();
window.location.href = event.currentTarget.href + window.location.search;
);
However this doesn't work for other elements on the page like buttons which are not anchor tags but still contain hrefs that modifiy the window location when they are clicked. For example in the php scripts of the theme there is code such as:
<button onClick="location.href=www.anotherwebsite.com"</button>
I could implement another function that implements the same behavior for button elements but I am concerned that whenever another element is added I will have to check for a new type. Is there a better way to ensure that whenever the window location is changed my query string persists?
FYI: I am not allowed to put the information in a cookie which is another way I thought of keeping track of the parameters.
javascript php jquery wordpress
I have a situation where I want to preserve a query string between clicks on my Wordpress website.
E.g.
www.mywebsite.com/?utm_source=mysource
When navigating from this link to another page of the website that query string should persist.
E.g.
www.mywebsite.com/anotherpage/?utm_source=mysource
So I decided one easy way to do this would be to modify the javascript so that my function is fired when a click on an anchor tag occurs.
//Ensures that the query string persists between clicks on the site
$("a").on("click", function (event)
event.preventDefault();
window.location.href = event.currentTarget.href + window.location.search;
);
However this doesn't work for other elements on the page like buttons which are not anchor tags but still contain hrefs that modifiy the window location when they are clicked. For example in the php scripts of the theme there is code such as:
<button onClick="location.href=www.anotherwebsite.com"</button>
I could implement another function that implements the same behavior for button elements but I am concerned that whenever another element is added I will have to check for a new type. Is there a better way to ensure that whenever the window location is changed my query string persists?
FYI: I am not allowed to put the information in a cookie which is another way I thought of keeping track of the parameters.
javascript php jquery wordpress
javascript php jquery wordpress
edited Mar 8 at 4:48
AdaRaider
asked Mar 8 at 4:23
AdaRaiderAdaRaider
671113
671113
Possible duplicate of Query string of referrer URL
– Steven Stark
Mar 8 at 4:30
The above doesn't solve my problem very eloquently as I would have to add the $referrer = $_SERVER['HTTP_REFERER']; to every script where the user is directed to a new link, if I had many pages in my website that could involve modifying a lot of code and writing a lot of duplicate code
– AdaRaider
Mar 8 at 4:37
that's only one of 3 answers though.
– Steven Stark
Mar 8 at 4:38
why not use sessions?
– tim
Mar 8 at 4:40
1
I found some older questions that suggest trying to intercept the location change using a beforeunload handler, but I am not too sure how reliably that would work. And there isn’t much else you could use to intercept just any arbitrary navigation event - history changes fire only when navigation happens via the browser history UI, but not for normal link or button clicks. // Seems a bit counter-intuitive that you want to not only track my initial visit to your page, but to keep sniffing after my a** as I navigate further through the site … but then have that requirement to not use cookies …?
– 04FS
Mar 8 at 8:52
|
show 3 more comments
Possible duplicate of Query string of referrer URL
– Steven Stark
Mar 8 at 4:30
The above doesn't solve my problem very eloquently as I would have to add the $referrer = $_SERVER['HTTP_REFERER']; to every script where the user is directed to a new link, if I had many pages in my website that could involve modifying a lot of code and writing a lot of duplicate code
– AdaRaider
Mar 8 at 4:37
that's only one of 3 answers though.
– Steven Stark
Mar 8 at 4:38
why not use sessions?
– tim
Mar 8 at 4:40
1
I found some older questions that suggest trying to intercept the location change using a beforeunload handler, but I am not too sure how reliably that would work. And there isn’t much else you could use to intercept just any arbitrary navigation event - history changes fire only when navigation happens via the browser history UI, but not for normal link or button clicks. // Seems a bit counter-intuitive that you want to not only track my initial visit to your page, but to keep sniffing after my a** as I navigate further through the site … but then have that requirement to not use cookies …?
– 04FS
Mar 8 at 8:52
Possible duplicate of Query string of referrer URL
– Steven Stark
Mar 8 at 4:30
Possible duplicate of Query string of referrer URL
– Steven Stark
Mar 8 at 4:30
The above doesn't solve my problem very eloquently as I would have to add the $referrer = $_SERVER['HTTP_REFERER']; to every script where the user is directed to a new link, if I had many pages in my website that could involve modifying a lot of code and writing a lot of duplicate code
– AdaRaider
Mar 8 at 4:37
The above doesn't solve my problem very eloquently as I would have to add the $referrer = $_SERVER['HTTP_REFERER']; to every script where the user is directed to a new link, if I had many pages in my website that could involve modifying a lot of code and writing a lot of duplicate code
– AdaRaider
Mar 8 at 4:37
that's only one of 3 answers though.
– Steven Stark
Mar 8 at 4:38
that's only one of 3 answers though.
– Steven Stark
Mar 8 at 4:38
why not use sessions?
– tim
Mar 8 at 4:40
why not use sessions?
– tim
Mar 8 at 4:40
1
1
I found some older questions that suggest trying to intercept the location change using a beforeunload handler, but I am not too sure how reliably that would work. And there isn’t much else you could use to intercept just any arbitrary navigation event - history changes fire only when navigation happens via the browser history UI, but not for normal link or button clicks. // Seems a bit counter-intuitive that you want to not only track my initial visit to your page, but to keep sniffing after my a** as I navigate further through the site … but then have that requirement to not use cookies …?
– 04FS
Mar 8 at 8:52
I found some older questions that suggest trying to intercept the location change using a beforeunload handler, but I am not too sure how reliably that would work. And there isn’t much else you could use to intercept just any arbitrary navigation event - history changes fire only when navigation happens via the browser history UI, but not for normal link or button clicks. // Seems a bit counter-intuitive that you want to not only track my initial visit to your page, but to keep sniffing after my a** as I navigate further through the site … but then have that requirement to not use cookies …?
– 04FS
Mar 8 at 8:52
|
show 3 more comments
1 Answer
1
active
oldest
votes
several suggestions
client side
In using jquery, it might be easier to just find clickable elements, or have the WordPress theme add css classes, if useful ones aren't there already.
server side
In WordPress, use sessions (but see below), and a rewrite or redirect rule using add_query_arg()
.
Note about sessions and WordPress: You can't rely on PHP sessions; instead use the database, perhaps via an existing plugin like WP Session Manager or WordPress Native PHP Sessions.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55056692%2fhow-to-keep-query-string-parameters-as-user-navigates-through-the-website%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
several suggestions
client side
In using jquery, it might be easier to just find clickable elements, or have the WordPress theme add css classes, if useful ones aren't there already.
server side
In WordPress, use sessions (but see below), and a rewrite or redirect rule using add_query_arg()
.
Note about sessions and WordPress: You can't rely on PHP sessions; instead use the database, perhaps via an existing plugin like WP Session Manager or WordPress Native PHP Sessions.
add a comment |
several suggestions
client side
In using jquery, it might be easier to just find clickable elements, or have the WordPress theme add css classes, if useful ones aren't there already.
server side
In WordPress, use sessions (but see below), and a rewrite or redirect rule using add_query_arg()
.
Note about sessions and WordPress: You can't rely on PHP sessions; instead use the database, perhaps via an existing plugin like WP Session Manager or WordPress Native PHP Sessions.
add a comment |
several suggestions
client side
In using jquery, it might be easier to just find clickable elements, or have the WordPress theme add css classes, if useful ones aren't there already.
server side
In WordPress, use sessions (but see below), and a rewrite or redirect rule using add_query_arg()
.
Note about sessions and WordPress: You can't rely on PHP sessions; instead use the database, perhaps via an existing plugin like WP Session Manager or WordPress Native PHP Sessions.
several suggestions
client side
In using jquery, it might be easier to just find clickable elements, or have the WordPress theme add css classes, if useful ones aren't there already.
server side
In WordPress, use sessions (but see below), and a rewrite or redirect rule using add_query_arg()
.
Note about sessions and WordPress: You can't rely on PHP sessions; instead use the database, perhaps via an existing plugin like WP Session Manager or WordPress Native PHP Sessions.
answered Mar 8 at 19:38
Loren RosenLoren Rosen
607
607
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55056692%2fhow-to-keep-query-string-parameters-as-user-navigates-through-the-website%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of Query string of referrer URL
– Steven Stark
Mar 8 at 4:30
The above doesn't solve my problem very eloquently as I would have to add the $referrer = $_SERVER['HTTP_REFERER']; to every script where the user is directed to a new link, if I had many pages in my website that could involve modifying a lot of code and writing a lot of duplicate code
– AdaRaider
Mar 8 at 4:37
that's only one of 3 answers though.
– Steven Stark
Mar 8 at 4:38
why not use sessions?
– tim
Mar 8 at 4:40
1
I found some older questions that suggest trying to intercept the location change using a beforeunload handler, but I am not too sure how reliably that would work. And there isn’t much else you could use to intercept just any arbitrary navigation event - history changes fire only when navigation happens via the browser history UI, but not for normal link or button clicks. // Seems a bit counter-intuitive that you want to not only track my initial visit to your page, but to keep sniffing after my a** as I navigate further through the site … but then have that requirement to not use cookies …?
– 04FS
Mar 8 at 8:52