java重定向到某个url

We know that the window object is like the mother of all objects in JavaScript and contains loads of different methods and properties attached to it. We have also seen some of them like localstorage, innerWidth, innerHeight, outerWidth and outerHeight, etc. Today we'll look at a property called location built on top of the window object that will allow us to redirect to different pages from one point.

我们知道, 窗口对象就像JavaScript中所有对象的母亲一样,并包含许多附加的不同方法和属性。 我们还看到了其中的一些变量 ,例如localstorage , innerWidth , innerHeight , externalWidth和externalHeight等。今天,我们来看一个建立在window对象顶部的位置属性,该属性使我们可以从一个点重定向到不同的页面。

Syntax:

句法:

    window.location = <url>;

The URL must be enclosed within quotations. Let's quickly try out inside the dev console of your browser. Go to any page and open the console and type in,

该URL必须用引号引起来。 让我们在浏览器的开发控制台中快速尝试一下。 转到任何页面并打开控制台并输入,

window.location = "https://www.facebook.com";

Hit enter and voila! You're redirected to facebook.com.

点击输入,瞧! 您已重定向到facebook.com。

We can also redirect to a page on loading the window. Let's see the following example,

我们还可以在加载窗口时重定向到页面。 让我们看下面的例子,

index.html

index.html

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script type="text/javascript">
function loadNewDoc() {window.location = "https://www.includehelp.com/";
}
</script>
</head>
<style>
.loader {margin: auto;
border: 16px solid brown;
width: 120px;
height: 120px;
border-top-color: violet;
border-bottom-color: violet;
border-radius: 50%;
animation: loaderAnimate 4s linear infinite;
}
@keyframes loaderAnimate {0% {transform: rotate(0deg) scale(1);
}
25% {border: 16px solid SlateBlue;
border-top-color: Tomato;
border-bottom-color: Tomato;
}
50% {transform: rotate(360deg) scale(1.1);
border: 16px solid orange;
border-top-color: yellow;
border-bottom-color: yellow;
}
75% {border: 16px solid DodgerBlue;
border-top-color: MediumSeaGreen;
border-bottom-color: MediumSeaGreen;
}
100% {transform: rotate(720deg) scale(1);
}
}
@keyframes appear {0% {opacity: 0;
}
100% {opacity: 1;
}
}
</style>
<body>
<body onLoad="setTimeout('loadNewDoc()', 5000)">
<h3>You will be redirected shorty...</h3>
<div class="loader"></div>
</body>
<script>
</script>
</html>

Output

输出量

And then we get the home page for includehelp.com

然后我们获得includehelp.com的主页

We have other redirection methods to redirect a URL to another page like location.replace(), localtion.assign() and location.reload().

我们还有其他重定向方法可以将URL重定向到另一个页面,例如location.replace()localtion.assign()location.reload()

location.replace() replaces the current document with a new one. We pass the new URL as a parameter to it and it performs an HTTP redirect. Similarly, we can also use location.assign().

location.replace()用新文档替换当前文档。 我们将新的URL作为参数传递给它,并执行HTTP重定向。 同样,我们也可以使用location.assign()

翻译自: https://www.includehelp.com/code-snippets/redirect-to-a-url-in-javascript.aspx

java重定向到某个url

java重定向到某个url_重定向到JavaScript中的URL相关推荐

  1. 取出url中的字符_如何在JavaScript中解析URL:例如主机名,路径名,查询,哈希?...

    统一资源定位符(缩写URL)是对Web资源(网页,图像,文件)的引用.URL指定资源位置和检索资源的机制(http,ftp,mailto). 例如,这是此博客文章的URL: 通常,您需要访问URL的特 ...

  2. java两字符串是否相等_Java与JavaScript中判断两字符串是否相等的区别

    JavaScript是一种常用的脚本语言,这也决定了其相对于其他编程语言显得并不是很规范.在JavaScript中判断两字符串是否相等 直接用==,这与C++里的String类一样.而Java里的等号 ...

  3. java dom 获得子元素_在JavaScript中删除DOM节点的所有子元素

    我将如何删除JavaScript中DOM节点的所有子元素? 说我有以下(丑陋的)HTML: hello world 我抓住了我想要的节点,如下所示: var myNode = document.get ...

  4. 过滤器过滤特定的url_如何从过滤器中排除URL

    过滤器过滤特定的url 默认情况下,过滤器不支持排除特定的URL模式,每当您为过滤器定义URL模式时,任何与该模式匹配的请求都将由过滤器无例外处理. 从过滤器中排除URL的最简单方法是将过滤器映射到非 ...

  5. Javascript中的url编码与解码(详解)

    摘要 本文主要针对URI编解码的相关问题做了介绍,对url编码中哪些字符需要编码.为什么需要编码做了详细的说明,并对比分析了Javascript中和编解码相关的几对函数escape / unescap ...

  6. java 访问器_网络之美 JavaScript中Get和Set访问器的实现代码

    标准的Get和Set访问器的实现 function Field(val){ this.value = val; } Field.prototype = { get value(){ return th ...

  7. javascript中new url()属性,轻松解析url地址

    1.首先写一个假的地址(q=URLUtils.searchParams&topic=api)相当于当前的window.location.href const urlParams = new U ...

  8. java上传图片到阿里云oss云存储中,返回url链接地址

    https://blog.csdn.net/baidu_38990811/article/details/78413470

  9. javascript中网页 url 与字符串之间的转换

    escape 和 unescape escape()不能直接用于URL编码,它的真正作用是返回一个字符的Unicode编码值. 采用unicode字符集对指定的字符串除0-255以外进行编码.所有的空 ...

最新文章

  1. RMI远程方法调用讲解教程
  2. 看完书要及时消化(1)《暗时间》
  3. 修改ActiveProcessLinks链表隐藏进程
  4. 什么是分布式系统中的幂等性
  5. 夏普电视android4.4.2,夏普电视怎么投屏 夏普电视投屏设置方法【详解】
  6. python配置日志的几种方式
  7. 实践分享:开始用Cordova+Ionic+AngularJS开发App
  8. foxpro:将表写入excel
  9. 安装qt5.9.5 windows环境
  10. 我们如何在Python中创建多行注释?
  11. UVALive 3401 彩色立方体
  12. Mean-shift超像素分割
  13. Java静态代理、动态代理
  14. 内存颗粒位宽和容量_内存颗粒有没有多与少的区别啊?或者说比较多的颗粒比少的颗粒好些?...
  15. python 循环高级用法 [expression for x in X [if condition] for y in Y [if condition] ... for n in N [if con
  16. 关于微信群、QQ群和其他发布平台
  17. 组合逻辑电路的设计:竞争和险象
  18. ai人工智能_药物发现中的人工智能
  19. 用python将txt文件中的内容导入到excel文件中
  20. win10重新安装ie

热门文章

  1. 最简单的python爬虫实战——爬取王者荣耀皮肤及头像
  2. 提高文章仿写效率,一个好用的智能AI伪原创工具是必备
  3. i7-1185G7怎么样 相当于什么水平
  4. jbd2 mysql_centos6下jbd2进程占用大量IO处理
  5. 量子计算入门学习笔记(六 量子测量-上 )
  6. android动态申请悬浮框权限,Android动态权限申请工具(包括悬浮窗)
  7. vivo用鸿蒙,鸿蒙要成功很简单:小米、OPPO、vivo都用上鸿蒙就行
  8. Mac 升级Python 2.7 到 Python 3.8
  9. android顶部工具栏和底部工具栏的简单实现代码,顶部和底部菜单栏TabLayout+ViewPager...
  10. webpack配置typescript详解