How can I associate two values in Javascript or Jquery? -
It seems that this should be easy to do but I can not find any practical solutions to the original idea code associated with the URL With an array and depending on whether the URL is parsed as a referral, a code is inserted in the local storage.
var site = {รข ???? Example1.com : "X10", an example? Example 2.com: "X11", an example? Example 3.com: "X12"} if (document.referrer.indexOf (site value)! = -1) {if (localStorage) {localStorage.setItem ("code", sitekey); }} So if the reference is example1.com, the code set locally will be "x10" and so on. I have probably read about using Underscore.JS_Invert method, but I think I should have a more clear solution. Lesson ">
It is slightly incompatible, because it finds matches after processing, but this is a very simple code:
Object.keys (site). ForEach (function ( Key) {if (document.referrer.indexOf (gtk)> gt; -1} {if (localStorage) {localStorage.setItem ("code", site [key]}}}}})
Update : Attention to the underscore tag. With underscores, I can make slight changes, instead of doing it: _. (Two pairs (site), function (pair) {if (document.referrer.indexOf (pair [0])> gt; -1) {if ( Localstorage), {localStorage.setItem ("code", pair [1]);}}}; The only important advantage is that they can work in the old environment which is Object.keys , or Array.prototype.forEach .
Comments
Post a Comment