by Don_HH2K » Sat 17 Dec, 2005 8:58 am
[tt]<!-- #include virtual="http://www.b.com/ad.html" -->[/tt] for ASP
[tt]<?php include('http://www.b.com/ad.html') ?>[/tt] for PHP
You can use HTML's [tt]iframe[/tt] element too...
- Code: Select all
<iframe src="http://www.b.com/ad.html" title="Ad" style="width: width-in-px; height: height-in-px;"></iframe>
(you can also use /> instead of [tt]</iframe>[/tt] if you're using XHTML)
You can also do it in JavaScript, although I wouldn't reccomend it (needs modern browsers supporting XMLHTTP).
Add this to your [tt]<head>[/tt] element:
- Code: Select all
<script>
function clientSideInclude(id, url) {
var req = false;
// For Safari, Firefox, and other non-MS browsers
if (window.XMLHttpRequest) {
try {
req = new XMLHttpRequest();
} catch (e) {
req = false;
}
} else if (window.ActiveXObject) {
// For Internet Explorer on Windows
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
req = false;
}
}
}
var element = document.getElementById(id);
if (!element) {
alert("Bad id " + id +
"passed to clientSideInclude." +
"You need a div or span element " +
"with this id in your page.");
return;
}
if (req) {
// Synchronous request, wait till we have it all
req.open('GET', url, false);
req.send(null);
element.innerHTML = req.responseText;
} else {
element.innerHTML =
"Sorry, your browser does not support " +
"XMLHTTPRequest objects. This page requires " +
"Internet Explorer 5 or better for Windows, " +
"or Firefox for any system, or Safari. Other " +
"compatible browsers may also exist.";
}
}
</script>
...then give [tt]<body>[/tt] an onLoad attribute, like this
- Code: Select all
<body>onLoad="clientSideInclude('adInclude', 'http://www.b.com/ad.html');">
...then create a <span> element with the ID [tt]adInclude[/tt] to tell the JS to dump the contents there.
- Code: Select all
<span id="adInclude"></span>
(alternatively you can use [tt]<span id="adInclude"/>[/tt] if you're using XHTML, but IE will choke on that)
UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051205 Donzilla/0.9 (WML/1.3)
Laptop: HP Compaq nx6325 - Turion 64 X2 @ 2GHz, 2GB DDR2, 100GB HD, ATI Radeon X300, 15" LCD, Seven Pro
Handheld: Palm Treo 650 - Intel PXA270 @ 312MHz, 10MB RAM, 32MB flash, 2.7" LCD, Palm OS 5.4