2012-11-13 2 views
0

내 페이지에 몇 가지 Google지도 소스가 있습니다. 이것들은 내 페이지를 느리게 만들므로, 페이지를로드 한 후에로드하고 싶었 기 때문에 이런 식으로 시도했습니다. 불행히도지도의 iframe 소스는 변경되지만지도는 내부에로드되지 않고 단지 비어 있습니다.iframe 소스를 동적으로로드 중입니다.

링크 :

<iframe width="300" height="300" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.co.in/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Megarugas+Banquet+and+Lawn,+Opp.+Chandivali+studio,&amp;aq=&amp;sll=19.127228,72.865035&amp;sspn=0.013259,0.022724&amp;ie=UTF8&amp;hq=Megarugas+Banquet+and+Lawn,+Opp.+Chandivali+studio,&amp;hnear=&amp;t=m&amp;cid=15174344858031542989&amp;ll=19.115165,72.894802&amp;spn=0.024329,0.025663&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe><br /><small><a href="https://maps.google.co.in/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=Megarugas+Banquet+and+Lawn,+Opp.+Chandivali+studio,&amp;aq=&amp;sll=19.127228,72.865035&amp;sspn=0.013259,0.022724&amp;ie=UTF8&amp;hq=Megarugas+Banquet+and+Lawn,+Opp.+Chandivali+studio,&amp;hnear=&amp;t=m&amp;cid=15174344858031542989&amp;ll=19.115165,72.894802&amp;spn=0.024329,0.025663&amp;z=14&amp;iwloc=A" style="color:#0000FF;text-align:left">View Larger Map</a></small> 

HTML :

<iframe id="blabla"></iframe> 

JS :

$(window).load(function() { 
    if ($('#blabla').length <= 0) { return; } // to avoid errors in case the element doesn't exist on the page/removed. 
    $('#blabla').attr('src','//example.com/page'); 
}); 

답변

1
src가 스크립트 내에서 구문 분석되지 않습니다

, 당신이 &amp;의 모든 occurencies를 교체해야합니다 &

당신 스스로 혼자 할 필요는 없습니다.

몇 가지 요소를 만듭니다 SRC에 HTML을 설정 한 다음 요소의 텍스트를 검색 :

$(window).load(function() { 
    $('#blabla').attr('src',$('<span/>').html('https://example.com/page').text()); 
}); 

추가 참고 : 당신은 당신 것, $('#blabla')의 길이를 확인 할 필요가 없습니다 jQuery 객체가 비어있을 때 오류를받지 않습니다.

+0

예. 문제가 해결되었습니다. 다시 ... thnx – warlock

관련 문제