// 使用 $(document).ready() $(document).ready(function(){ // 这里写入需要在页面加载完成后执行的代码 var fullUrl = window.location.href; if (fullUrl.includes('.html') || fullUrl.includes('.htm')) { // 使用 split() 方法分割字符串以获取域名 var parts = fullUrl.split('/'); var domainWithProtocol; // 如果包含协议(如 https:// 或 http://),则获取协议和域名部分 if (parts[0].includes('http:') || parts[0].includes('https:')) { domainWithProtocol = parts[0] + '//' + parts[2]; } else { domainWithProtocol = parts[0] + '//' + parts[1]; } console.log(domainWithProtocol); $.post(domainWithProtocol+'/baiduapi.php', { "url": fullUrl, "hao": "javawjs" }, function(response) { // 请求成功后的回调函数 console.log(response); }); }else{ console.log(fullUrl); console.log('我爱你') } });