从iFrame重定向窗口

时间:2017-11-20 06:56:35

标签: javascript c# asp.net iframe

我希望有人可以协助解决我目前遇到的问题。我在客户端网站上实现了名为 IFrame1 IFrame。在客户端网站上,他们在QueryString中拥有该用户的某些信息,例如clientwebsite.com/login.aspx?UserID=xxxx&UserName=xxxx

使用MVC什么是检索整个查询字符串的最佳方式,而我在网站上只有IFrame

我尝试使用JavaScript检索window.location,但这只会显示部署IFrame的网址(MyServer.com),而不会显示已实施的网址(clientwebsite.com) )。我也尝试过使用C#HttpRequest.QueryString。这也只显示我部署解决方案的URL,而不是客户端网站URL。

如果有人有任何建议,我们将不胜感激。

修改

我尽可能多地尝试使用window.parent.location。我写了一个小网页,我只需将代码拉出来并显示如下:

<script type="text/javascript">
    document.write("window.location.href : " + window.location.href + "<br />");
    document.write("window.parent.location : " + window.parent.location + "<br />");
    document.write("document.referrer : " + document.referrer + "<br />");
</script>

当我运行此页面时,我得到如下结果:

window.location.href http://mywebsite.com/test
window.parent.location http://mywebsite.com/test
document.referrer 

哪个好,但是当我通过客户端网站查看时,它只显示href值,但不显示window.parent.location标签或值。这可能是由于权限造成的吗?

1 个答案:

答案 0 :(得分:0)

你应该尝试使用:

var parentUrl = window.parent.location;

window.parent将让您进入父窗口,然后您可以对父窗口执行任何操作。

嗨鲁宾,

我相信你需要添加window.parent.location.search。您可以对查询字符串执行类似的操作。这个答案由Marwan提供:

function getQueryString() {
            var queryStringKeyValue = window.parent.location.search.replace('?', '').split('&');
            var qsJsonObject = {};
            if (queryStringKeyValue != '') {
                for (i = 0; i < queryStringKeyValue.length; i++) {
                    qsJsonObject[queryStringKeyValue[i].split('=')[0]] = queryStringKeyValue[i].split('=')[1];
                }
            }
            return qsJsonObject;
        }

只需从子窗口调用它,并以查询字符串作为对象。

例如,如果您有查询字符串?name = stack并且想要获取它,请尝试:

getQueryString().name

这将返回堆栈。

相关问题