Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get iframe src param from inside the iframe itself

Tags:

jquery

iframe

i have an iframe and need to capture the src attribute inside a javascript variable. This is how my iframe looks like

<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>

I am able to get the name through window.name but not the src attribute. Any idea?

like image 318
Leon Avatar asked Apr 19 '12 15:04

Leon


1 Answers

If allowed by cross-domain checks, try window.frameElement.src. Otherwise, you are out of luck and left alone with location.href.

like image 103
Alexander Pavlov Avatar answered Oct 11 '22 01:10

Alexander Pavlov