这篇文章主要介绍“javascript中怎么使用window.location对象实现页面跳转”,在日常操作中,相信很多人在javascript中怎么使用window.location对象实现页面跳转问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”javascript中怎么使用window.location对象实现页面跳转”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

window.location对象用于获得当前页面的地址(URL),并把浏览器重定向到新的页面。
window location 对象在编写时可不使用Window这个前缀。一些例子:
location.hostname返回web主机的域名
location.pathname返回当前页面的路径和文件名
location.port返回web主机的端口
location.protocol返回所使用的的web协议
window location href
示例
返回当前页面的URL:
<script type="text/javascript">
document.write(location.href);
</script>
以上代码输出为:
http://127.0.0.1:8848/7.11/new_file.html
window location pathname
location.pathname属性返回URL的路径名。
示例
返回当前URL的路径名:
<script type="text/javascript">
document.write(location.pathname);
</script>
以上代码输出为:
/7.11/new_file.html
window location Assign
location.assign()方法加载新的文档。
示例
加载一个新的文档:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<input type="button" name="" id="" value="跳转到百度" onclick="newDoc()"/>
<script type="text/javascript">
function newDoc(){
window.location.assign('https://www.baidu.com')
}
</script>
</body>
</html>
使用javascript实现页面定时跳转---location对象
要求实现以下效果:

代码实现思路:
实现代码如下:
html代码:

css代码:

js代码:
实现效果:

到此,关于“javascript中怎么使用window.location对象实现页面跳转”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注天达云网站,小编会继续努力为大家带来更多实用的文章!