简体   繁体   中英

Javascript function that can return me the cxd

Hello im new in Javascript please someone can help me to create a function that can return me the cxd value my code is this but i need to return me like a value, not console.log or alert .

var url_str = 'http://blablabla=Cell&utm_mediun=test&cxd=cxd_2288_356025';
var url = new URL(url_str).searchParams.get('cxd').split('_');
console.log(url1[1]);

 function getCxdSearchParam(url) { return new URL(url).searchParams.get('cxd').split('_')[1]; } console.log(getCxdSearchParam('http://somedomin.com?blablabla=Cell&utm_mediun=test&cxd=cxd_2288_356025'));

Try using

var url_str = 'http://blablabla=Cell&utm_mediun=test&cxd=cxd_2288_356025';    
const urlParams = new URLSearchParams(url_str);
const searchParam = urlParams.get('cxd');
const data = searchParam.split('_');
console.log(data[1]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM