简体   繁体   中英

JavaScript display remote content

I'm building an affiliate system and in interested in knowing which would be the most reliable way to display remote banners. I mean for the affiliates to grab a piece of code and use it to display banners, it whatever on their sites.

Doesnt have to be JavaScript and I'm using php

The two simplest ways I can think of are:

  1. To have the server side generate an image, like Mathias said, then the affiliate would need to add something like <img src="http://your.site.name/script.php"> .

  2. Have the affiliate use an iframe, then you can return whatever HTML you need, and they need to add something like <iframe src="http://your.site.name/script.php"> to their pages.

Google ads, on the other hand, use javascript to generate that iframe, which gives them greater flexibility, at the cost of a more complex solution on their end.

I strongle suggest u to use ajax

Sample javascript ajax codes

<html>
<head>
<script type="text/javascript">
function loadXMLDoc()
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>

<div id="myDiv"><h2>Let AJAX change this text</h2></div>
<button type="button" onclick="loadXMLDoc()">Change Content</button>

</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM