I am trying to loop through a few iframes to grab the src of the iframes and remove a particular query string from the src of those iframes. This is what I have so far:
$(document).ready(function() {
$('iframe').each(function() {
var $src = $(this).attr('src').substring(0, $(this).attr('src').indexOf('&id'));
alert($src);
});
});
iframe {
width: 300px height:300px;
background: #fafafa;
margin: 20px auto;
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<iframe src="mysite.com/program.asp?name=abc&status=3&id=2"></iframe>
<iframe src="mysite.com/program.asp?id=2"></iframe>
The first url of the iframe displays correctly but the second url of the second iframe does not.
The expected output:
first iframe - mysite.com/program.asp?name=abc&status=3
second iframe - mysite.com/program.asp?