访问iframe的URL客户端

时间:2014-12-09 23:36:54

标签: javascript html iframe google-chrome-extension

我正在构建Chrome扩展程序。当用户点击网址栏附近的Chrome浏览器右侧的扩展按钮时,我会弹出一个弹出框。

弹出框包含iFrame。

我想获得iframe的URL客户端。这是我迄今为止的尝试。

popup.html

<!doctype html>
    <html>
          <body style="width:300px height:400px" >
      <iframe id="framey" frameBorder="0" src="https://localhost:5000/login" width="300" height="400">
          <body>
      </iframe>
      <script src="popup.js"></script>

      <button>Click for to get the iframe URL!</button>

    </html>

popup.js

document.addEventListener('DOMContentLoaded', function () {
  document.querySelector('button').addEventListener('click', clickHandler);
});

function clickHandler(e) {
    var iframe_URL = document.getElementById("framey").contentWindow.location.href;
    console.log("The url is", iframe_URL);

}

这会导致以下错误

Uncaught Security Error: Blocked a frame with origin "chrome-extension://ldpopcacdgmhjjahdmhiongcigbpfmjm" from accessing a frame with origin "https://localhost:5000".  The frame requesting access has a protocol of "chrome-extension", the frame being accessed has a protocol of "https". Protocols must match.

这有什么办法吗?

0 个答案:

没有答案