window.location

编程入门 行业动态 更新时间:2024-10-28 04:17:12
window.location - javascript - 无效(window.location - javascript - not working)

奇怪的问题。 我正在使用jQuery .postMessage()将消息从安全的<iframe>发送到父级。 具体来说,我发送一个URL并确认父接收URL - 但是,当我使用try将window.location设置为该URL时,没有任何反应。

发送的网址:

http://mydomain.com/shop/507870?nav=ln-474#/shop/507870?gnrefine=1*COLOR_FAMILY*Brown%5E1*CLSR_TYP*Lace-Up%5E

实际网址:

http://mydomain.com/shop/507870?nav=ln-474#/shop/507870?gnrefine=1*COLOR_FAMILY*Brown%5E1*CLSR_TYP*Lace-Up%5E

他们相配。 但是,在Chrome中,如果我执行console.log(loginConfig.redirectURL); 我明白了:

http://mydomain.com/shop/507870?nav=ln-474#/shop/507870?gnrefine=1*COLOR_FAMILY*Brown%5E1*CLSR_TYP*Lace-Up%5E

undefined
 

所以,我认为window.location正在获取undefined值。

有什么想法,当我使用console.log时,为什么我会得到两个值?

更新

逻辑:

if (message[1] != "") { $("#loginDialog").dialog("close"); loginConfig.redirectURL = message[1]; window.location = loginConfig.redirectURL console.log('message: '+loginConfig.redirectURL); }

配置对象:

var loginConfig = { redirectURL: "" }

进一步更新:

window.location适用于任何没有哈希的url。 所以出于某种原因,它不会加载任何带有哈希的url。

Odd issue. I am using jQuery .postMessage() to send messages from a secure <iframe> to the parent. Specifically I am sending a URL and have confirmed that the parent is receiving the URL - however, when I use try to set window.location to that URL, nothing happens.

The sent url:

http://mydomain.com/shop/507870?nav=ln-474#/shop/507870?gnrefine=1*COLOR_FAMILY*Brown%5E1*CLSR_TYP*Lace-Up%5E

The actual url:

http://mydomain.com/shop/507870?nav=ln-474#/shop/507870?gnrefine=1*COLOR_FAMILY*Brown%5E1*CLSR_TYP*Lace-Up%5E

They match. However, in Chrome, if I do a console.log(loginConfig.redirectURL); I get:

http://mydomain.com/shop/507870?nav=ln-474#/shop/507870?gnrefine=1*COLOR_FAMILY*Brown%5E1*CLSR_TYP*Lace-Up%5E

undefined
 

So, I think the window.location is getting the undefined value.

Any thoughts on why I would be getting two values when I use the console.log?

Update

logic:

if (message[1] != "") { $("#loginDialog").dialog("close"); loginConfig.redirectURL = message[1]; window.location = loginConfig.redirectURL console.log('message: '+loginConfig.redirectURL); }

config object:

var loginConfig = { redirectURL: "" }

Further Update:

the window.location works on any url without a hash. So for some reason, it will not load any urls with a hash.

最满意答案

这部分代码无效:

var loginConfig = { redirectURL = "" }

它必须是这样的:

var loginConfig = { redirectURL: "" }

如果这导致一个错误,该错误使loginConfig无法正确声明所需的属性,这可能部分解释了一些意外行为。 您当然应该查看浏览器错误日志,看看它是否报告任何错误。

This part of your code is invalid:

var loginConfig = { redirectURL = "" }

It needs to be this:

var loginConfig = { redirectURL: "" }

If this leads to an error which keeps loginConfig from being properly declared with the desired property that could partly explain some unexpected behavior. You should certainly look in your browser error log and see if it reports any errors.

更多推荐

本文发布于:2023-07-18 03:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1154197.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:window   location

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!