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. TSS和内核态堆栈的关系
  2. c语言如何输出斜杠星号,Excel 如何提取出最后一个斜杠开始的数字
  3. ssm打印sql如何开启_mybatis怎么配置log4j打印出sql语句
  4. 自定义checkbox样式
  5. Ubuntu 18.04-20.04开机自动root用户登录(测试可用)
  6. 神奇的python(四)之logging日志文件系统
  7. git在跟踪bug中的使用
  8. python中从键盘输入列表_在python中为列表使用原始输入
  9. MySQL 5.7主从复制从零开始设置及全面详解——实现多线程并行同步,解决主从复制延迟问题!
  10. Java Swing 如何关闭当前窗口?
  11. python counter 出现次数最少的元素_[PY3]——找出一个序列中出现次数最多的元素/collections.Counter 类的用法...
  12. MySQL 8.0 OCP 1Z0-908认证考试题库1
  13. Google关停中国区域翻译服务后继续使用Chrome自带翻译插件的方法教程
  14. 【笔记】MySQL 根据出生日期计算当前年龄
  15. Ethereum ETH的奖励机制
  16. 计算机健康小知识,电脑一族护肤保健小常识
  17. 介绍一个产品的思维导图_产品经理可以用思维导图做什么?
  18. Qt焦点事件 setFocusPolicy
  19. 1004.【一维数组】【入门】输出奇数和偶数
  20. Houdini 节点

热门文章

  1. 如何在IDEA上配置使用Git
  2. 含麒麟芯片的华为手机值得买吗?
  3. 华为服务器修改root密码,服务器root密码修改
  4. 使用uuid作为数据库主键,被技术总监怼了一顿!
  5. 一款炫酷的H5视频播放插件
  6. 【订单服务】库存解锁和关单
  7. 地图的相关使用(定位,地理编码,导航)
  8. Vue下 touchstart touchend 事件无效失效解决办法
  9. 花菁染料CY5标记WS2二硫化钨纳米粒CY5-WS2 NPs|CY5-Se-PEG-WS2
  10. 百度地图无法实现重复定位的问题