난 로렌아줌마가 호메이사믈 div id = ";;; '에서' < 로드하기에 content" >.
<div id="topBar"> <a href ="#" onclick="load_home()"> HOME </a> </div>
<div id ="content"> </div>
<script>
function load_home(){
document.getElementById("content").innerHTML='<object type="type/html" data="home.html" ></object>';
}
</script>
이 때 사용하고 Firefox 작동합니다. 구글 크롬, 이 때 내가 사용하는 플러그-인을 묻습니다. 구글 크롬 일하던 이해했소 어떻게 합니까?
Jquery 로드형 기능을 사용할 수 있습니다.
<div id="topBar">
<a href ="#" id="load_home"> HOME </a>
</div>
<div id ="content">
</div>
<script>
$(document).ready( function() {
$("#load_home").on("click", function() {
$("#content").load("content.html");
});
});
</script>
죄송합니다. 대신 클릭하면 대한 편집됩니다 로드.
function load_home (e) {
(e || window.event).preventDefault();
fetch("http://www.yoursite.com/home.html" /*, options */)
.then((response) => response.text())
.then((html) => {
document.getElementById("content").innerHTML = html;
})
.catch((error) => {
console.warn(error);
});
}
function load_home (e) {
(e || window.event).preventDefault();
var con = document.getElementById('content')
, xhr = new XMLHttpRequest();
xhr.onreadystatechange = function (e) {
if (xhr.readyState == 4 && xhr.status == 200) {
con.innerHTML = xhr.responseText;
}
}
xhr.open("GET", "http://www.yoursite.com/home.html", true);
xhr.setRequestHeader('Content-type', 'text/html');
xhr.send();
}
ajax 및 smartupdate 콩지름에 구속을 따라 해당 javascript 로드되었는지 수정표시와 전에 ' () 함수를 호출하는 load_home'
[참조 - 데이비드 월시] (https://davidwalsh.name/fetch)
[매든 - 페치할 사용하여] (https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch)
그래서 난 그때 내가 본 결과 매우 좋은 실행했음 일부 정보기술 (it) 이 보인다.
하지만 이 같은 외곽진입 청소하십시오 것처럼 보일 수도 있습니다 성능 면에서 떨어지는 데 걸린 시간이 무려 50% 가 있는 페이지 스믈하트프리퀘스트 의 javascript 를 사용하여 로드하십시오 jQuery 로드형 함수 또는 바닐라 외곽진입 있던 약 서로 비슷하다.
이 때문에 내가 상상도 할 수 있는 것은 역시 동일한 방식으로 해당 페이지의 후드요 it gets a whole new 사마를레먼트 건설 계약을 로케이터로 설명이다.
간단히 말해 내가 사용하는 제안하세요 포함한다. 될 수 있기 때문에 쉽게 사용할 수 있는 것처럼 대한 구문은 또한 아주 잘 구조화된 전화를 사용할 수 있습니다. 또 상대적으로 빠른. 이 구문은 눈에 띄지 않지만, 바닐라 외곽진입 속도가 더 빨라질 수 있습니다) 에 의해 몇 밀리초입니다 혼란스럽다. 나는, 내가 didn& # 39 만 t 이 환경에서는 액세스하도록 포함한다.
다음은 코드를 사용하는 것이 아니라 내가 여러 번 테스트하려면 - 그래서 저는 아주 아주 초보적인 부활하셨잖아요 일관적이며 각각의 경우에 약 + - 5ms 의 정확히까지 말할 것이다. 크롬 from my home server 의 자체 테스트는 실행하십시오.
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
</head>
<body>
<div id="content"></div>
<script>
/**
* Test harness to find out the best method for dynamically loading a
* html page into your app.
*/
var test_times = {};
var test_page = 'testpage.htm';
var content_div = document.getElementById('content');
// TEST 1 = use jQuery to load in testpage.htm and time it.
/*
function test_()
{
var start = new Date().getTime();
$(content_div).load(test_page, function() {
alert(new Date().getTime() - start);
});
}
// 1044
*/
// TEST 2 = use <object> to load in testpage.htm and time it.
/*
function test_()
{
start = new Date().getTime();
content_div.innerHTML = '<object type="text/html" data="' + test_page +
'" onload="alert(new Date().getTime() - start)"></object>'
}
//1579
*/
// TEST 3 = use httpObject to load in testpage.htm and time it.
function test_()
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
content_div.innerHTML = xmlHttp.responseText;
alert(new Date().getTime() - start);
}
};
start = new Date().getTime();
xmlHttp.open("GET", test_page, true); // true for asynchronous
xmlHttp.send(null);
// 1039
}
// Main - run tests
test_();
</script>
</body>
</html>
이 같은 기능을 Javascript '근대' 와 '외곽진입 사용, 비동기식 / 기다리는 페치할' 제공한다. 그 후 이를 통해 컨테이너입니다 '' 이너사믈 급지됩니다 텍스트로 다운로드하며 HTML 요소.
/**
* @param {String} url - address for the HTML to fetch
* @return {String} the resulting HTML string fragment
*/
async function fetchHtmlAsText(url) {
return await (await fetch(url)).text();
}
// this is your `load_home() function`
async loadHome() {
const contentDiv = document.getElementById("content");
contentDiv.innerHTML = await fetchHtmlAsText("home.html");
}
기다리고 있는 ' (페치할 (url) 를 기다리는) .text ()' 의 쉽게 보일 수 있습니다, 하지만 조금 까다로운 it& # 39 설명해보게. 이 함수는 다음과 같은 단계를 2 개를 가지고 있으며 비동기적입니다 재작성할 수 있습니다
async function fetchHtmlAsText(url) {
const response = await fetch(url);
return await response.text();
}
자세한 내용은 [페치할 API 문서를] (https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) 참조.
시도하시겠습니까
async function load_home(){
content.innerHTML = await (await fetch('home.html')).text();
}
<! - begin 스니핏: js 숨기십시오: 진정한 콘솔: 진정한 바벨. > 거짓값 -;
async function load_home() {
let url = 'https://kamil-kielczewski.github.io/fractals/mandelbulb.html'
content.innerHTML = await (await fetch(url)).text();
}
<div id="topBar"> <a href="#" onclick="load_home()"> HOME </a> </div>
<div id="content"> </div>
끝 - < 스니핏 >;!
$("button").click(function() {
$("#target_div").load("requesting_page_url.html");
});
또는
document.getElementById("target_div").innerHTML='<object type="text/html" data="requesting_page_url.html"></object>';
이것은 일반적으로 에이드리프프 또는 포함할 때 필요한 모든 페이지.
자바 가상 머신 (jvm) 에 it& # 39 의 경우에는 더욱 쉽게 t want to use php, HTML 페이지 및 don& # 39 포함시키십시오 정보기술 (it) 을 쓰기 기능을 추가하고 작동하지만 전혀 jave 태그이고, php 스크립트 기능을 합니다.
이 경우 이름 뒤에 쓸 필요 없이 그냥 기능을 한다. 분노 스크립트입니다 단어 및 시작합니다. 에이드리프프 포함시키십시오 함수 I. ᅦ 변환하십시오 php 스크립트 기능을 포함한 모든 내용을 태그와 함수 포함시키십시오 jave 배치하십시오 절실해졌습니다.
내가 don& 프레임워크와도 t # 39, 또는 사용하여 라이브러리 ( 슬래시나 정말 내 클라이언트뿐 5월 매핑하려는) 내 웹 플랫폼 isn& 과도한 부담을 안고 있지만, t # 39 에서 고 성공했다. 아래는 제가 직접 쓴 후 추가 기능을 위한 XML 을 '', '전', '내부' () 가 마지막 요소) 또는 '굈' 및기존 요소. 이너사믈 '쓰레기' 와 같은 신뢰할 수 없다 (즉 대부분의 브라우저에서 필요 'id' " added"; # 39 이 길을 찾을 수 없다, 즉, can& 수 없다). 다음은 이 게시물 하단에 있는 독립형 필수 기능 사용 예제.
function xml_add(pos, e, xml)
{
e = (typeof e == 'string' && id_(e)) ? id_(e) : e;
if (e.nodeName)
{
if (pos=='after') {e.parentNode.insertBefore(document.importNode(new DOMParser().parseFromString(xml,'application/xml').childNodes[0],true),e.nextSibling);}
else if (pos=='before') {e.parentNode.insertBefore(document.importNode(new DOMParser().parseFromString(xml,'application/xml').childNodes[0],true),e);}
else if (pos=='inside') {e.appendChild(document.importNode(new DOMParser().parseFromString(xml,'application/xml').childNodes[0],true));}
else if (pos=='replace') {e.parentNode.replaceChild(document.importNode(new DOMParser().parseFromString(xml,'application/xml').childNodes[0],true),e);}
//Add fragment and have it returned.
}
}
Ajax 를 통해 xml dom 单捞磐啊 로드중 인되며 제대로 xml 이름공간 ('xmlns 를 = ", http://www.w3.org/1999/xhtml",') 의 루트 요소를 수도 있습니다 필터링되지 둘 경우 스크립트루트 요소이거나 보관합니까 반복할 수 있을 것이다). '다음' 임포트노데 사용해야 합니다. 그냥 여기서 나머지 기능은 시맨틱스를 (아약스, 다른 함수 등) 는 XML 의 배치할 수 있는 다른 요소를 기준으로 DOM.
element.appendChild(new DOMParser().parseFromString('<div xmlns="http://www.w3.org/1999/xhtml">'+id_('post_body').value+'</div>'),'application/xml'.childNodes[0]);
이후 추가 xlm '' 특정 요소:
xml_add('after', id_(push_current_id()).tag_('footer')[0], '<div class="hidden" id="editor_rich_temp"></div>');
전에 추가 xlm '' 특정 요소:
xml_add('before', $('#'+push_current_id()+' section')[0], '<h2 xmlns="http://www.w3.org/1999/xhtml"><span>Compose Message</span></h2>');
'추가 xlm' 인사이드라면 특정 요소 (되는 마지막 하위 요소로):
xml_add('inside', $('body > header > nav')[1], xml);
다음은 내가 사용하는 기능을 on my 플랫폼 사용자를 위해 5 명과 함께 처벌하는 복제본입니다 프레임워크와도 / 라이브러리보다는 높고 높은 성능을 보장합니다.
function $(o) {var r = false; if (document.querySelectorAll) {r = document.querySelectorAll(o);} return r;}
function class_(c) {return (document.getElementsByClassName(c)) ? document.getElementsByClassName(c) : false;}
function tag_(t) {return (document.getElementsByTagName(t)) ? document.getElementsByTagName(t) : false;}
Object.prototype.$ = function(c) {return (this.querySelectorAll && this.querySelectorAll(c) && this.querySelectorAll(c).length > 0) ? this.querySelectorAll(c) : false;}
Object.prototype.class_ = function(c) {return (this.getElementsByClassName && this.getElementsByClassName(c) && this.getElementsByClassName(c).length > 0) ? this.getElementsByClassName(c) : false;}
Object.prototype.tag_ = function(t) {return (this.getElementsByTagName && this.getElementsByTagName(t) && this.getElementsByTagName(t).length > 0) ? this.getElementsByTagName(t) : false;}
내가 코드 진단트리로 계기로 업데이트하십시오 드물게 (같도다라고 it& # 39 의 견고한 아닌 version" "; 따라 다름). # 39 의 JavaScript it& 벽돌이날아와 피하기 위해 낮은 성능 및 프로그래밍 순결케 의해 쉽게 프레임워크와도 라이브러리보다는. https://www.jabcreations.com/docs/javascript/ # 기능ᆞ기술과
쇼히데스트믈
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function showHide(switchTextDiv, showHideDiv)
{
var std = document.getElementById(switchTextDiv);
var shd = document.getElementById(showHideDiv);
if (shd.style.display == "block")
{
shd.style.display = "none";
std.innerHTML = "<span style=\"display: block; background-color: yellow\">Show</span>";
}
else
{
if (shd.innerHTML.length <= 0)
{
shd.innerHTML = "<object width=\"100%\" height=\"100%\" type=\"text/html\" data=\"showhide_embedded.html\"></object>";
}
shd.style.display = "block";
std.innerHTML = "<span style=\"display: block; background-color: yellow\">Hide</span>";
}
}
</script>
</head>
<body>
<a id="switchTextDiv1" href="javascript:showHide('switchTextDiv1', 'showHideDiv1')">
<span style="display: block; background-color: yellow">Show</span>
</a>
<div id="showHideDiv1" style="display: none; width: 100%; height: 300px"></div>
</body>
</html>
showhide_embedded.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function load()
{
var ts = document.getElementById("theString");
ts.scrollIntoView(true);
}
</script>
</head>
<body onload="load()">
<pre>
some text 1
some text 2
some text 3
some text 4
some text 5
<span id="theString" style="background-color: yellow">some text 6 highlight</span>
some text 7
some text 8
some text 9
</pre>
</body>
</html>