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?













0















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.










share|improve this question
























  • 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
















0















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.










share|improve this question
























  • 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














0












0








0


1






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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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













1 Answer
1






active

oldest

votes


















1














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.






share|improve this answer






















    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
    );



    );













    draft saved

    draft discarded


















    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









    1














    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.






    share|improve this answer



























      1














      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.






      share|improve this answer

























        1












        1








        1







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 8 at 19:38









        Loren RosenLoren Rosen

        607




        607





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

            2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme