2016-06-30 3 views
0

iframe의 URL을 확인하려고하지만 실제 URL이 필요하지 않다는 사실을 깨달았습니다. URL이 내 도메인에 있는지 여부를 알 수 있습니다. iframe URL에 대한 액세스가 거부되었습니다.

은 내가
document.getElementById("frameid").documentWindow.location.href 

를 사용할 수 있습니다 및 URL이 내 도메인 내에 있지 않은 경우는 오류를 반환합니다 생각. 하지만이 오류를 가로채는 방법은 무엇입니까?

+0

http://stackoverflow.com/questions/16213943/window-onerror-does-not-catch-all-errors/16214094#16214094 – CBroe

답변

0

내가 가지고있는 의견의 게시물은 도움이되었지만 내 자신의 게시물을 찾지 못했기 때문에 다른 사람이 비슷한 질문을하면 여기에 최종 해결책을 게시 할 것입니다.

$('#iFrame').on('load', function() { 
    try { 
     // checks if iframe content is internal 
     test = this.contentWindow.document.location.href; 
     showIframe = false; 
    } 
    catch (err) { 
     // if an error is thrown, iframe content is external 
     showIframe = true; 
    } 

    if (showIframe) { 
     // do some stuff 
    } 
} 
관련 문제