从iframe内部获取iframe src参数

Leo*_*eon 9 iframe jquery

我有一个iframe,需要捕获javascript变量中的src属性.这就是我的iframe的样子

<iframe id="iframe_module_46081" name="iframe_module_46081" src="//myurl.com/tabs/495/campaigns/0ed3ffa8-5050-4a18-a5e3-f348d12a1304?signature=6aa3005368f163539976460246f2f0839c0fb3e3&amp;id=678326">
<script>$(document).ready(function(){
  var name = window.name;
  var src = ????;
})
</script>
</iframe>
Run Code Online (Sandbox Code Playgroud)

我可以通过window.name获取名称,但不能通过src属性获取名称.任何的想法?

Ale*_*lov 18

如果跨域检查允许,请尝试window.frameElement.src.否则,你运气不好,独自一人location.href.

  • `frameElement`的+1,我总是忘记存在 (3认同)
  • 因为iframe可能已经远离其原始位置 (2认同)