有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java获取url地址,其中是包含我的页面的iframe

我有一个问题:

有些页面有iframe,它们在其中显示我的服务

我的服务是用Java编写的

是否有可能通过iframe获取显示我的页面的页面的url地址(参考者)

谢谢


共 (1) 个答案

  1. # 1 楼答案

    如果您试图从iFrame获取主页的url,则只有当它们位于同一子域中时才有可能

    Access parent URL from iframe

    Yes, accessing parent page's URL is not allowed if the iframe and the main page are not in the same (sub)domain. However, if you just need URL of the main page (i.e. the browser URL), you can try this

    var url = (window.location != window.parent.location) ? document.referrer: document.location;