it-source

페이지 로드 시 웹 페이지 콘텐츠를 어떻게 div에 로드할 수 있습니까?

criticalcode 2023. 3. 7. 21:34
반응형

페이지 로드 시 웹 페이지 콘텐츠를 어떻게 div에 로드할 수 있습니까?

iframe을 사용하지 않고, 다음의 내용을 로드할 수 있습니까?

<div id="siteloader"></div>

외부 사이트(somesitehere.com 등)를 사용하는 경우

페이지가 언제 로딩됩니까?-파일에서 콘텐츠를 로딩하는 방법은 알지만 사이트 전체를 로딩하는 방법은 몰랐습니까?

대단히 고맙습니다,

이 작업은 다음 작업 없이 수행할 수 있습니다.iframe구체적으로는 jQuery가 제목에 언급되어 있기 때문에 활용되고 있습니다.

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Load remote content into object element</title>
  </head>
  <body>
    <div id="siteloader"></div>​
    <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
    <script>
      $("#siteloader").html('<object data="http://tired.com/">');
    </script>
  </body>
</html>

jQuery의 .load() 함수를 확인합니다.

<script>
    $(function(){
        $('#siteloader').load('http://www.somesitehere.com');
    });
</script>

다만, 이것은 JS 파일의 같은 도메인에서만 동작합니다.

jQuery를 사용하면 가능하지만 Ajax를 사용하지 않습니다.

function LoadPage(){
  $.get('http://a_site.com/a_page.html', function(data) {
    $('#siteloader').html(data);
  });
}

그리고 장소onload="LoadPage()"본문 태그에 넣어주세요.

이 루트를 따르면 php 버전이 더 나을 수 있습니다.

echo htmlspecialchars(file_get_contents("some URL"));

AJAX를 사용하여 다른 사이트(도메인)의 콘텐츠를 삽입할 수 없습니다.이러한 경우에 iFrame이 적합한 이유는 다른 도메인에서 소스를 지정할 수 있기 때문입니다.

언급URL : https://stackoverflow.com/questions/9963799/how-can-i-load-webpage-content-into-a-div-on-page-load

반응형