I have a script (JS) that parses the URL suffixes and then from that data defines variables.
THE URL: http://www.example.com/somepage.html?bg=white&&accent=gray
var PAGE = {
bg: location.href.match(/bg=(.*)/)[1],
accent: location.href.match(/accent=(.*)/)[1]
};
alert("Page Background: " + PAGE.bg + " \n Page Complements: " + PAGE.accent);
Note, the url gets its params from a page I created that goes before visiting that page (the user clicks a variety of options, then hits a “Next” button).
Everything works pretty well, except the PAGE.bg returns white&&accent=gray, obviously returning everything after bg=. I want to know how to only return the BG, so like do a parseFloat of PAGE.bg or something like that, but being a beginner at JavaScript, I don’t know how to do it, and it’s kind of a detailed problem so I didn’t have any luck googling it. Any ideas? Any help would be much appreciated.
Try the following instead: