The example in this article describes the method of JS implementation to obtain keywords from Baidu, Google, soso, and sogou. Share it with everyone for your reference, the details are as follows:
/*Get the user, which keyword is used to access the page, and you can add SOGOU, SOSO, Youdao and other search engines by yourself*/ var refer=document.referrer; var sosuo=refer.split(".")[1]; var grep=null; var str=null; var keyword=null; switch(sosuo){ case "baidu": grep=/wd\=.*\&/i; str=refer.match(grep) keyword=str.toString().split("=")[1].split("&")[0]; console.log(decodeURIComponent(keyword)); break; case "google": grep=/&q\=.*\&/i; str=refer.match(grep) keyword=str.toString().split("&")[1].split("=")[1]; console.log(decodeURIComponent(keyword)); break; }
Readers who are interested in more Javascript-related content can check out the special topics of this site: “Summary of Javascript Search Algorithm Techniques”, “Summary of Javascript Data Structure and Algorithm Techniques”, “Summary of Javascript Traversal Algorithms and Techniques”, “JSON in Javascript” Summary of Operation Skills”, “Summary of Javascript Switching Special Effects and Techniques”, “Summary of Javascript Animation Special Effects and Techniques”, “Summary of Javascript Errors and Debugging Techniques” and “Summary of Javascript Mathematical Operation Usage”
I hope this article will be helpful to everyone in Javascript programming.