There are a couple of ways you could go about this; I'm going to cover an AJAX/PHP method to dynamically get the desired content and place it on your page.
Essentially there are 2 parts to this, the first is a simple AJAX function on your main page that will tell a PHP script to get some data for you from another site/page. The second part is the PHP script which will fetch the contents of another page and send it back to your AJAX function.
Code:
<script type="text/javascript">
function setReqObj() {
var nAjax;
if(window.XMLHttpRequest) {
nAjax = new XMLHttpRequest();
} else {
nAjax = new ActiveXObject("Microsoft.XMLHTTP");
}
return nAjax;
}
function _LoadExtData($url, $id, $div) {
var xmlhttp = setReqObj();
if(xmlhttp) {
xmlhttp.onreadystatechange=function() {
if(xmlhttp.readyState == 4) {
var $content = xmlhttp.responseText;
document.getElementById($div).innerHTML = $content;
}
}
$data = "url=" + $url + "&id=" $id;
xmlhttp.open("POST", "location/toPHP/script.php", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send($data);
}
}
</script>
Essentially, the way this is set up to work is that you will have a .php file saved on your server (make sure to set the "location/toPHP/script.php" to the proper location of this .php file) and then you will also add the javascript code to any page you want to use this on. Whenever you'd like (on the click of a button, on the page load, etc) you can call the _LoadExtData() function in which you need to specificy 3 things: the page url to grab data from (www.otpx.com), the ID of the element you want to grab content from (div2) and the element you want to put this data in (div1).
"Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"
Let's start with the clone() method in jQuery. While it does seem to have a similar concept to what you need (making a duplicate of any elements in a selector), it would only be of use if the data was on the same page.
In your original post you note that you seem to want to get the contents of a div from one page (on one domain) and place them in to a div on another page (on a different domain). Because of these pages being on different domains, it means AJAX or iframes would be useless due to cross-domain policy restrictions. jQuery does offer some cross-domain AJAX solutions but I'm not familiar enough with those to be certain they will or will not solve your problem.
In the end, it doesn't matter if you code in asp, jsp, php, java or any language at all; I have included the entire source code for what you would need to accomplish this. As long as your web server/host supports PHP then everything should work without any trouble. The PHP code posted is the entire file and you would merely need to update the AJAX code so that it uses whatever filename you set for this PHP file. From there you will have a fully functional way of grabbing any data from one div (or any element) on any page (given it has an id attribute set and you know the id) and place this data inside of any element on your own page.
"Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"
So essentially, once you have that PHP code copied into a new file and saved it as 'whatever.php' you just need to insert that script anywhere on your page (but in the <head> tags would be a good idea for tidy code). Make sure you also update the javascript so that it sends and gets data from the php file you just created:
Code:
xmlhttp.open("POST", "whatever.php", true);
As far as 'defining' the url and div id go, this is something that depends entirely on you. Just based on your example in your original post it would be something like
This is assuming you have this code/function on the site with the second url you listed: http://www.otpx.com/
The last thing I should mention is that I noticed the first site was using frames. Theoretically, this shouldn't cause any problems but I have personally never tested a script like this with sites that use frames so it's hard to say if there will be any problems. If there are it would have to be adjusted to check for frames and then find your data.
"Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"
Bookmarks