Using following code i want to get href of <A>
but <A>
could be at any number of inner iframes. Basically we are trying to fetch url on which our advertisement is redirecting and because of nested structure of iframe we are not able to fetch that url.
CODE:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div style="width:300px;border:1px solid #000;" id="test">
<SCRIPT SRC="http://ib.adnxs.com/ttj?id=3234436&cb=${CACHEBUSTER}&referrer=${REFERER_URL}&pubclickenc=${CLICK_URL_ENC}" TYPE="text/javascript"></SCRIPT>
</div>
<script TYPE="text/javascript">
var href='';
function recurring(target){
$(target).each(function(){
var obj=$(this);
var tagNm=($(this).prop("tagName"));
alert(tagNm);
if(tagNm.toUpperCase()=='DIV'){
recurring($(this).find("*"));
}
else if(tagNm.toUpperCase()=='IFRAME'){
console.log(obj);
recurring(obj.find('body'));
}
else if(tagNm.toUpperCase()=='A'){
if($(this).attr("href")!="" && $(this).attr("href")!=undefined){
alert('if->'+$(this).attr("href"));
href=($(this).attr("href"));
}
}
});
}
$(document).ready(function(e) {
recurring($('#test'));
//alert('34');
alert('my href->'+href);
});
</script>
</body>
</html>