前后端获取url
作者:互联网
一、js获取页面url
// --获取域名 www.xxx.com
var domain = document.domain;
var domain = window.location.host;
// --获取url,不含参数 http://www.xxx.com/JDYmdyPGph.php/pim/schedule
var url= window.location.protocol+"//"+window.location.host+""+window.location.pathname;
// --获取整个url,带参数 http://www.warning.com/JDYmdyPGph.php/pim/schedule?addtabs=1
var url = window.location.href;
var url = self.location.href;
var url = document.URL;
var url = document.location;
// --只获取当前url的参数 addtabs=1
function GetUrlPara()
{
var url = document.location.toString();
var arrUrl = url.split("?");
var para = arrUrl[1];
return para;
}
二、php获取url
$_SERVER["REQUEST_URI"] apache支持
// 说明:获取完整URL function curPageURL() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") { $pageURL .= "s"; } $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; } return $pageURL;
标签:url,前后,SERVER,获取,window,pageURL,location,var 来源: https://www.cnblogs.com/cmooc/p/16351812.html