I’m trying to create a program on my server that enables me to pull information from different websites. It’s already written in PHP and works perfectly. I gather this information from an iframe on one of my pages. When I use the original page that was loaded by the php script in the iframe, everything works fine. But, if I click on a link inside of the iframe, the src is different and I don’t know how to access it. How do I figure out the NEW src of the <iframe> with jQuery? I searched this site and can’t find a good answer to this. Below is an example of my code:
the PHP:
<?php
$link = $_POST['link'];
?>
<div id="button">Button</div>
<iframe src="<? echo $link;?>"></iframe>
<script type="text/javascript" src="something.com/jquery.js"></script>
<script type="text/javascript">
$('#button').click(function()
{
//alert iframe src
});
</script>
EDIT:
I current have this running, and it only alerts the original src when I click a link in the <iframe>. I’m needing it to alert the NEW src of the <iframe>.
<iframe id="blog_iframe" onload="iframeLoader();" height="600px" width="98%" src="<? echo $url;?>" scrolling="auto">
<p>Your current browser does not support iFrames. Please use a different browser</p>
</iframe>
<script type="text/javascript">
function iframeLoader()
{
alert($('iframe').attr("src"));
}
</script>
Use .attr()
** EDIT **
According to Edited question.
You’re actually trying to get src of <a> tag inside of <iframe> tag
Try this