2

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>
Stephan Muller
  • 27,018
  • 16
  • 85
  • 126
Dipen
  • 240
  • 1
  • 5
  • 17
  • I know the question is almost same but if you try above code than you can get idea that both contains are different and in my content that method is not working properly. – Dipen Sep 22 '14 at 14:38

0 Answers0