用 Javascript 可以单独获取当前域名.Url.相对路径和参数,所谓单独攻取,即域名不包括网页文件的路径和参数.参数不包括域名和网页文件路径,下面分别介绍. 一.js获取当前域名有2种方法 1.方法一 var domain = document.domain; 2.方法二 var domain = window.location.host; 3.注意问题 由于获取到的当前域名不包括 http://,所以把获取到的域名赋给 a 标签的 href 时,别忘了加上 http://,否则单击链接…
一.js获取当前域名有2种方法 1.方法一 var domain = document.domain; 2.方法二 var domain = window.location.host; 3.注意问题 由于获取到的当前域名不包括 http://,所以把获取到的域名赋给 a 标签的 href 时,别忘了加上 http://,否则单击链接时导航会出错. 二.获取当前Url的4种方法 var url = window.location.href; var url = self.location.href…
1.Ajax获取接口数据 function demo(){ //假设请求参数 var requestBody = [{ "name":"zhang", "age":"18" }]; //将值转换为JSON字符串 requestBody = JSON.stringify(requestBody); //发起Ajax请求 $.ajax({ //url填自己的 url:"", type:"post&qu…
console.log(window.location.host) console.log(document.domain) console.log(window.location.href) console.log(window.domain) 地址栏: 输出:…
当前url:http://localhost:805/test/helloworld.php echo 'SERVER_NAME:'.$_SERVER['SERVER_NAME']; //获取当前域名的后缀(不含端口号) echo '<p>'; echo 'HTTP_HOST:'.$_SERVER['HTTP_HOST'];//获取当前域名 (含端口号) echo '<p>'; echo 'REQUEST_URI:'.$_SERVER['REQUEST_URI'];//获取当前域名…
/** * 获取顶级域名 * @param $url * @return string */ public static function getDoMain($url){ if(empty($url)){ return ''; } if(strpos($url,'http://') !== false){ $url = str_replace('http://','',$url); } if(strpos($url,'https://') !== false){ $url = str_repl…
以下代码整理于网络 1.设置或获取对象指定的文件名或路径. window.location.pathname 例:http://localhost:8086/topic/index?topicId=361 alert(window.location.pathname); 则输出:/topic/index 2.设置或获取整个 URL 为字符串. window.location.href 例:http://localhost:8086/topic/index?topicId=361 alert(wi…
1.基础url的获取 #测试网址: http://localhost/blog/testurl.php?id=5 //获取域名或主机地址 echo $_SERVER['HTTP_HOST']."<br>"; #localhost //获取网页地址 echo $_SERVER['PHP_SELF']."<br>"; #/blog/testurl.php //获取网址参数 echo $_SERVER["QUERY_STRING"…
window.location方法后还还可以带href,search等参数,下面我们来看看获取url各项参数的办法. URL即:统一资源定位符 (Uniform Resource Locator, URL)完整的URL由这几个部分构成:scheme://host:port/path?query#fragmentscheme:通信协议常用的http,ftp,maito等 http://localhost/test/test.htm?id=1代码如下 复制代码 <html><head>…
window.location方法后还还可以带href,search等参数,下面我们来看看获取url各项参数的办法. URL即:统一资源定位符 (Uniform Resource Locator, URL)完整的URL由这几个部分构成:scheme://host:port/path?query#fragmentscheme:通信协议常用的http,ftp,maito等 http://localhost/test/test.htm?id=1代码如下 复制代码 <html><head>…