How to refresh a page with jQuery by passing a parameter to URL

后端 未结 9 1462
借酒劲吻你
借酒劲吻你 2020-12-13 17:04

I am refreshing my page using jQuery:

location.reload();

This is working great but I want to refresh the same page by passing a parameter t

9条回答
  •  庸人自扰
    2020-12-13 17:48

    You can use Javascript URLSearchParams.

    var url = new URL(window.location.href);
    url.searchParams.set('single','');
    window.location.href = url.href;
    

    [UPDATE]: If IE support is a need, check this thread:

    SCRIPT5009: 'URLSearchParams' is undefined in IE 11

    Thanks @john-m to talk about the IE support

提交回复
热议问题