vendredi 23 octobre 2015

javascript regex for querysting with anchor

I am making a web app that has multiple 'pages' but it will all be loaded client side. Seems how it is all technically on the same page, I will be using parameters after # to track the current page state while preventing postbacks. My problem is that I cant seem to select all the parameters with a regex line. The regex for split works when I use a testing tool online but does not work when I use it on my web page.

//Test data for url
//http://ift.tt/1R1LuAS

var split = /([^&#=]+)=?([^&#]*)/g;
var url = window.location.href;
var match = split.exec(url);

//this outputs match with a length of three 
//[0] = 'https://test.ca?hi'
//[1] = 'https://test.ca?hi'
//[2] = ''

I thought this should be a solved problem but I cant seem to find an answer. Which I guess leads to another question. Am I going about this the completely wrong way?

Aucun commentaire:

Enregistrer un commentaire