旧代码:window.parent.location.href="https:/home" [英] Legacy code: window.parent.location.href="https:/home"

查看:26
本文介绍了旧代码:window.parent.location.href="https:/home"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从我们以前的开发人员那里继承了一些代码,我找到了这段代码.

I have inherited some code from our former developer and I found this piece of code.

<?php
   if($this->loginAction->isAuthenticated()){
?>
   <script type="text/javascript">
      window.parent.location.href="https:/home";
   </script>
<?php
}
?>

我已经研究了一段时间,但我不知道他为什么把 URL 的快捷方式放在那里.我认为 URL 应该是 https://mysite.com/home.我基本上不知道这段代码是做什么的.

I have been looking on it for a while and I have no idea why he put there the shortcut for the URL. I think that the URL should be https://mysite.com/home. I basically don't know what does this code do.

我知道如果用户通过身份验证,此代码是重定向,但我不知道奇怪的 URL(https:/home) 在那里做什么.此代码有效.

I know that this code is redirection if user is authenticated, but I don't know what the strange URL(https:/home) is doing there. This code is working.

感谢您的帮助.

Edit2: 据我同事说,这是 JS 的秘密之一:) 去测试一下.这两行代码应该具有相同的功能:

According to my colleague, this is one of the JS secrets:) Going to test it. This two lines of code should have equal functionality:

window.parent.location.href="https:/home";
window.parent.location.href="https://www.my-testing.com/home";

推荐答案

这是 URI,根据此处的规范是有效的:https://www.ietf.org/rfc/rfc2396.txt 在第 3 节中引用如下:(粗体和突出显示是我的)这表示该方案 https 后跟分隔符冒号 : 然后其余部分是可选的.因此,单个正斜杠可能被解释为https://home"的根或完整"URI,或者只是当前的/home"提供者.如果您的网站是 www,则可能看起来像https://www.example.com/home".example.com(它不是但在规范中也作为保留名称),它是您站点的 DNS 地址.请注意,如果该方案缺少//www.ourbug.ne​​t",那么它将被转换为当前使用的方案(大多数资源为 http 或 https)

This is the URI and it is valid according to the spec here: https://www.ietf.org/rfc/rfc2396.txt in section 3 as quoted here: ( the bold and highlights are mine) This says that the scheme https followed by the separator colon : then the rest is optional. Thus the single forward slash is likely interpreted as the root or "full" URI of "https://home" or simply the "/home" of the current provider. Likely this then looks like "https://www.example.com/home" if your site is www.example.com (it isn't but that one is in the specifications as a reserved name as well) which is the DNS address of your site. Note that if the scheme were missing as "//www.ourbug.net" then that would be translated into the current scheme in use (http or https for most resources)

3.URI 语法组件

URI 语法取决于方案.一般来说,绝对URI 写成如下:

The URI syntax is dependent upon the scheme. In general, absolute URI are written as follows:

  <scheme>:<scheme-specific-part>

绝对 URI 包含正在使用的方案的名称 ()后跟一个冒号(:"),然后是一个字符串(the ),其解释取决于方案.

An absolute URI contains the name of the scheme being used () followed by a colon (":") and then a string (the ) whose interpretation depends on the scheme.

URI 语法不要求方案特定部分具有所有通用的任何一般结构或语义集URI.然而,URI 的一个子集确实共享一个通用的语法表示命名空间内的层次关系.这个通用 URI"语法由四个主要部分组成:

The URI syntax does not require that the scheme-specific-part have any general structure or set of semantics which is common among all URI. However, a subset of URI do share a common syntax for representing hierarchical relationships within the namespace. This "generic URI" syntax consists of a sequence of four main components:

  <scheme>://<authority><path>?<query>

除了 之外,每个都可能不存在于特定的 URI 中.例如,某些 URI 方案不允许组件,而其他人不使用组件.

each of which, except , may be absent from a particular URI. For example, some URI schemes do not allow an component, and others do not use a component.

  absoluteURI   = scheme ":" ( hier_part | opaque_part )

本质上是分层的 URI 使用斜杠/"字符表示分离分层组件.对于某些文件系统,/"字符(用于表示 URI 的层次结构)是用于构造文件名层次结构的分隔符,因此 URIpath 将类似于文件路径名.这并不意味着资源是一个文件或者 URI 映射到一个实际的文件系统路径名.

URI that are hierarchical in nature use the slash "/" character for separating hierarchical components. For some file systems, a "/" character (used to denote the hierarchical structure of a URI) is the delimiter used to construct a file name hierarchy, and thus the URI path will look similar to a file pathname. This does NOT imply that the resource is a file or that the URI maps to an actual filesystem pathname.

  hier_part     = ( net_path | abs_path ) [ "?" query ]

  net_path      = "//" authority [ abs_path ]

  abs_path      = "/"  path_segments"

这篇关于旧代码:window.parent.location.href="https:/home"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆