javascript - get iframe src in a page loaded via jquery $.get? -


i'm loading page using $.get, page load has iframe. know iframe id, reason cant src value...

assuming code

function loadpage(postid) {      $.get("/post/" + postid,     function(data) {          var p = $(data).find("iframe").attr('src');         console.log(p)      }) } 

i undefined result...

but console of data object complete valus need...i'm not sure if problem of selecting in right way

the following should work:

$.get('/somescript', function(result) {     var framesource = $('iframe', result).attr('src');     alert(framesource); }); 

here's live demo. make sure not violating same origin policy. that's why it's better use relative urls when performing ajax requests (/somescript).


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -