奇怪的问题。 我正在使用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%5EThe actual url:
http://mydomain.com/shop/507870?nav=ln-474#/shop/507870?gnrefine=1*COLOR_FAMILY*Brown%5E1*CLSR_TYP*Lace-Up%5EThey 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 undefinedSo, 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.
更多推荐
发布评论