check if a query string item is set in the current url

this will check and console log if a query string on this page is set to test=anything

example url is: 

Test is not set: https://kruxor.com/view/code/XzLaT/ 

Test is set using & : https://kruxor.com/view/code/XzLaT/&test=moo 

Test is set using ? : https://kruxor.com/view/code/XzLaT/?test=moo 

Javascript

var field = 'test';
var url = window.location.href;
if(url.indexOf('?' + field + '=') != -1) {
   console.log('test is set with ?');
} 
if (url.indexOf('&' + field + '=') != -1) {
 	console.log('test is set with &');
}

Other Items in javascript

No Items Found.

Add Comment
Type in a Nick Name here
 
Page Views

This page has been viewed 281 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹

Random Quote
time you enjoyed wasting is not wasted time
Unknown