对于网站建设来说,通常会需要遇到js跨域抓取的问题,那么对于初学者来说,都不知道该怎么来解决,对此,郑州网站建设公司淘金科技就来跟大家好好的分析解答一下吧。
源代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script>
var url;
url = window.location.href; /* 获取完整URL */
alert(url); /* http://127.0.0.1:8020/Test/index.html#test?name=test */
url = window.location.pathname; /* 获取文件路径(文件地址) */
alert(url); /* /Test/index.html */
url = window.location.protocol; /* 获取协议 */
alert(url); /* http */
url = window.location.host; /* 获取主机地址和端口号 */
alert(url); /* http://127.0.0.1:8020/ */
url = window.location.hostname; /* 获取主机地址 */
alert(url); /* http://127.0.0.1/ */
url = window.location.port; /* 获取端口号 */
alert(url); /* 8020 */
url = window.location.hash; /* 获取锚点(“#”后面的分段) */
alert(url); /* #test?name=test */
url = window.location.search; /* 获取属性(“?”后面的分段) */
alert(url);
/* 如果需要URL中的某一部分,可以自己进行处理 */
url = window.location.pathname;
url = url.substring(url.lastIndexOf('/') + 1, url.length);
alert(url); /* /index.html */
/*
* 如果页面使用了框架(frameset)
* 要获取到指定页面的URL
* 只要把window换成指定的页面即可
*/
/* 'frame'为指定页面的class名 */
var url = window.parent.frames['frame'].location.href;
/* 获取当前地址栏中显示的URL */
var url = window.parent.location.href;
/* window parent 可互换 */
var url = parent.window.location.href;
</script>
</head>
<body>
</body>
</html>
现在,大家都知道如何有效的解决js跨域抓取的问题了吧,如果还是存在不理解的地方,可以留言咨询郑州网站建设公司淘金科技,我们可以共同学习进步。
学习 Photoshop 有很多方法,例如上课、看书...
什么是网站栏目,说白一些就是网站的导航栏,也就是用户访问...
在Android开发中,有些技术人员可能对于JieCao...
对于网站建设来说,通常会需要遇到js跨域抓取的问题,那么...
亮度蒙版是影调调整的基石。它提供了一个简便的方法来选取图...
请扫二维码联系客服
854221200@qq.com
185-3825-9583
QQ客服
关于  ·  招聘  ·  案例中心  ·  网站地图
(c)@2018 淘金科技版权所有 豫ICP备16015002号-4
百度提供搜索支持