2014-01-22 3 views
0

iframe이 하나 있고 버튼이 3 개 필요합니다. 일단 button1을 클릭하면 url이 두 번째 버튼과 같은 iframe에 표시되어야합니다. 여기 내 코드입니다, 도와 주시겠습니까.자바 스크립트를 사용하여 Iframe에 표시되는 URL

function testCoverage(){  
    window.frames['idIfrm'].document.location.href = 'http://google.com'; 
    } 
function testCoverage1(){ 
    window.frames['idIfrm'].document.location.href = 'http://yahoo.com'; 
} 

여기가 머리에 자바 스크립트 온로드를 실행하도록 설정되어 있지 않기 때문에

답변

1

처럼

<div> 
    <button><a href="http://www.computerhope.com/banners/banner.gif" target="iframe_a">Banner1</a></button> 
    <button><a href="http://www.computerhope.com/banners/banner2.gif" target="iframe_a">Banner2</a></button> 
    <button><a href="http://www.computerhope.com/banners/banner3.gif" target="iframe_a" onclick="closeWindow();">Banner3</a></button> 
    <div>  
    <iframe src="http://www.computerhope.com/banners/banner3.gif" name="iframe_a" width="900" height="350px" id="iframe" frameborder="0" scrolling="no" style="margin-left:15px;margin-bottom:15px;border:none;"> 
    </iframe> 
    </div> 
</div> 
1

JsFiddle이 당신의 바이올린은 실행되지 않습니다이다. 왼쪽 상단의 드롭 다운 메뉴를 변경하십시오.

enter image description here

두 번째 문제, 당신은 iframe이 아닌 문서 위치의 소스를 설정해야합니다.

window.frames['idIfrm'].src = "foo.html"; 

Google은 아무 것도 할 수없는 제 3의 문제는 iframe에 넣을 수 없습니다. 당신은 '의 X 프레임 - 옵션' 'SAMEORIGIN'로 설정 때문에

이 프레임에 ' https://www.google.com/'을 표시하는 거부 오류를 얻을 것이다.

+0

을 보일 것 I는 구글 맵을 표시하고 싶습니다. – Rajasekhar

+0

[google map api] (https://developers.google.com/maps/)를 사용하십시오! – epascarello

1

src 특성을 사용해야합니다. 코드는 실제로 여기, 내 말에 잘 작동이 코드를 시도하십시오이

function testCoverage(){ 
     document.getElementById['idIfrm'].src = 'http://google.com'; 
    } 
    function testCoverage1(){ 
     document.getElementById['idIfrm'].src = 'http://yahoo.com'; 
    } 
+0

나는 이것을 보았지만 행운이 없었다. – Rajasekhar

관련 문제