Javascript turns the relative path into the absolute path example
- 2020-03-30 02:23:51
- OfStack
There are essentially two ways to do this, either by creating the DOM or by using JavaScript:
function getAbsoluteUrl(url){
var img = new Image();
img.src = url; //Set the relative path to the Image, and the request is sent
url = img.src; //Now the relative path has become the absolute path
img.src = null; //Cancel the request
return url;
}
getAbsoluteUrl("showroom/list");
Thus it can be seen that the original ecological method is used to access all images. When Anchor, the absolute path is returned. If you want to return to the original relative path, you can query DOM, such as jQuery.
//Return the absolute path. JQuery objects are essentially an "array of classes" structure (like arguments), so use [0] to access the original object, and then "href";
console.log($anchor[0]["href"]);
//Return to original path
console.log($anchor.attr("href"));