JavaScript:读取父页面的URL

时间:2017-08-16 16:50:47

标签: javascript jquery iframe

我有一个内部加载的页面。包含此页面的应用程序位于另一个域中。因此,我的网页域和在iframe中呈现它的应用程序位于不同的域中。 iframe中的页面读取它加载的URL以存储在数据库中。页面加载在URL中有一个哈希。它就像:

<section class="container">
  <div class="columns">
    <div class="column">
      <div class="flex-card">
        <div class="card-content">
          <p class="blog-category">Expert Strategies</p>
          <div class="columns">
            <p class="column blog-title">Pivot to Purchase</p>
            <p class="column blog-meta text-right">August 8, 2017 <br>Podcast #18</p>
          </div>
          <p class="blog-description">If technology can be a disruptor - it will. Zillow has a pilot program that...</p>
          <button>Read More</button>
        </div>
      </div>
      <footer class="align-bottom-container">
        <a class="spreaker-player" href="https://www.spreaker.com/user/kellyguest/expert-strategies-audit-your-brand" data-resource="episode_id=11390290" data-theme="light" data-autoplay="false" data-playlist="false" data-width="100%" data-height="200px">Listen to "Expert Strategies:  Audit Your Brand" on Spreaker.</a>
        <script async src="https://widget.spreaker.com/widgets.js"></script>
      </footer>
    </div>
    <div class="column">
      <div class="flex-card">
        <div class="card-content">
          <p class="blog-category">Expert Strategies</p>
          <div class="columns">
            <p class="column blog-title">Pivot to Purchase</p>
            <p class="column blog-meta text-right">August 8, 2017 <br>Podcast #18</p>
          </div>
          <p class="blog-description">
            <div>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Temporibus voluptatibus provident inventore velit impedit maxime asperiores consequuntur, ex veritatis libero aspernatur itaque quidem, harum accusamus dolorem, vel similique delectus
              distinctio.
            </div>
          </p>
          <button>Read More</button>
        </div>
      </div>
      <footer><a class="spreaker-player" href="https://www.spreaker.com/user/kellyguest/expert-strategies-audit-your-brand" data-resource="episode_id=11390290" data-theme="light" data-autoplay="false" data-playlist="false" data-width="100%" data-height="200px">Listen to "Expert Strategies:  Audit Your Brand" on Spreaker.</a>
        <script async src="https://widget.spreaker.com/widgets.js"></script>
      </footer>
    </div>
  </div>
</section>

我正在阅读mypage中的网址。它位于:     https://www.someotherdomain.com/organizers/#sample

https://www.somedomain.com/organizers/list/#type=current&sort=bydate

以上代码为我提供了网址,但仅限&#34; https://www.somedomain.com/organizers/list/&#34;,&#34; #type = current&amp; sort = bydate&#34; 失踪。我需要其他代码对我没用。有没有办法可以阅读完整的网址而不会错过任何细分?

2 个答案:

答案 0 :(得分:0)

像这样     var _url = window.location;

答案 1 :(得分:0)

这是设计的。浏览器将为您提供引用者,该引用者是用户来自的URL,但是#hashmark在技术上(通过其原始设计)是页面中的子导航概念,因此不会传递给下一页加载。

如果您与父页面位于同一个域中,则可以通过

访问它
window.parent.location.hash

但是,由于您来自不同的域,出于安全原因,此访问可能会被阻止。