[ meraklija @ 11.10.2006. 11:00 ] @
| Cilj: ucitati sadrzaj u DIV koji se nalazi u drugom frejmu (bez linka za klik misem).
Prva strana (sadrzi iframe):
<HEAD>
<script type="text/javascript">
function ajaxLoader(url,id) {
if (document.getElementById) {
var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
}
if (x) {
x.onreadystatechange = function() {
if (x.readyState == 4 && x.status == 200) {
document.getElementById(id).innerHTML = x.responseText;
}
}
x.open("GET", url, true);
x.send(null);
}
}
</script>
</HEAD>
<BODY>
<script>ajaxLoader('ja.html','ovde')</script>
<iframe name="drugi" src="ti.html" width=100 height=50 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no></iframe>
</BODY>
Sadrzaj fajla ti.html je:
<BODY>
<div id="ovde"></div>
</BODY>
Svasta sam pokusao ali jos nisam uspeo da ucitam fajl ja.html u DIV koji se nalazi u iframe. Pa, ideja je dobrodosla... |
[ Br@nkoR @ 11.10.2006. 11:46 ] @
Code:
<html>
<HEAD>
<script type="text/javascript">
function ajaxLoader(url,id) {
if (document.getElementById) {
var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
}
if (x) {
x.onreadystatechange = function() {
if (x.readyState == 4) {
var iframe = document.getElementById('frejm');
if (typeof iframe.contentDocument != 'undefined') {
var iframeContent = iframe.contentDocument;
} else if(typeof iframe.contentWindow != 'undefined') {
var iframeContent = iframe.contentWindow.document;
} else if(typeof iframe.document != 'undefined') {
var iframeContent = iframe.document;
} else {
alert ('error');
return false;
}
iframeContent.getElementById(id).innerHTML = x.responseText;
}
}
x.open("GET", url, true);
x.send(null);
}
}
window.onload = function() {
ajaxLoader('ja.html','ovde');
}
</script>
</HEAD>
<BODY>
<iframe id="frejm" onload="" name="drugi" src="ti.html" width=100 height=50 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no></iframe>
</BODY>
</html>
[ meraklija @ 11.10.2006. 13:03 ] @
Da, ...ali ne prolazi obrnuto, iz iframe u _parent
Pokusavam da proradi sa linijom:
document.getElementById('frame').target="_parent" // zadam naziv frejma
Gornji kod bi skratio samo na:
...
if (x.readyState == 4) {
document.getElementById('frejm').contentWindow.document.getElementById(id).innerHTML = x.responseText;
}
...
[ Br@nkoR @ 11.10.2006. 15:48 ] @
Code:
parent.document.getElementById(id).innerHTML = x.responseText;
Copyright (C) 2001-2025 by www.elitesecurity.org. All rights reserved.