Estoy actualizando mi página usando jQuery:
location.reload();Esto funciona muy bien, pero quiero actualizar la misma página pasando un parámetro a la URL.
¿Cómo puedo hacer esto usando jQuery?
Ex:
Si mi URL es www.myweb.com , quiero actualizar esto pasando un parámetro como este
www.myweb.com?singleGracias
Debería poder lograr esto usando location.href
if(window.location.hostname == "www.myweb.com") window.location.href += "?single";Usaría REGEX con .replace así:
window.location.href = window.location.href.replace( /[\?#].*|$/, "?single" );Puede usar Javascript URLSearchParams .
var url = new URL(window.location.href); url.searchParams.set('single',''); window.location.href = url.href;[ACTUALIZAR]: si necesita soporte para IE, consulte este hilo:
SCRIPT5009: 'URLSearchParams' no está definido en IE 11
Gracias @john-m por hablar sobre el soporte de IE