Remote Code Script

Need technical advice on coding your web pages? Covers HTML, JavaScript, CSS, and some server side technologies. Also the issue of some webpages not displayed well.

Moderator: Don_HH2K

Remote Code Script

Postby Ron Williams » Fri 16 Dec, 2005 11:26 pm

I want to be able to change code that is displayed on sites that contain my ads. For example, a site inserts a piece of code. This does something like inserting a remote image does. So instead of there being code on the site, what you see is the code that i have in a remote location.

So say the site I have displaying content is http://www.a.com

There site has there code, but then displays then uses the code I have at http://www.b.com/ad.html

What script (or other thing) can do this?
UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5
User avatar
Ron Williams
BANNED
BANNED
 
Posts: 845
Joined: Tue 25 Nov, 2003 9:47 am
Location: Cambridge, Maryland

Postby 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
User avatar
Don_HH2K
Moderator
Moderator
 
Posts: 5112
Joined: Sun 09 May, 2004 3:59 pm


Return to Web Design and Page Coding

Who is online

Registered users: Antony, Bing [Bot], Google [Bot]