0

I try to use text variable from file from another site. Site contains only one value - number. On my site I added IFRAME:

<iframe id="counter" src="http://xxxx/counter.txt">

Then I was trying to take value from IFRAME by using this code:

<script type="text/javascript"> 
onload = function () {
    var ball = document.getElementById('counter');
    var div = document.getElementsByTagName('XcounterX')[0];
    div.innerHTML = ball;
};
</script>

The last point is to display var as html value by:

<XcounterX> Result </XcounterX>

Full html:

<body>
<iframe id="counter" src="http://xxxx/counter.txt">

<script type="text/javascript"> 
onload = function () {
    var ball = document.getElementById('counter');
    var div = document.getElementsByTagName('XcounterX')[0];
    div.innerHTML = ball;
};
</script>

<XcounterX> Result </XcounterX>
</body>

Unfortunately it doesn't work. Java complitly is something new for me. Can you help? I also try:

<script>
    $(document).ready(function(){
    $.ajax({
    url: "http://xxxx/counter.txt",
    dataType: 'html',
    context: document.body,
    success: function(data){
      $("#XcounterX").empty;
      $("#XcounterX").html(data);
  }
});
</script>

<div id='XcounterX'></div>

Same result. :(

1 Answers1

0

If I had your code, I would test those things (without conviction).

1. JS pure

<script type="text/javascript"> 
  onload = function () {
    var ball = document.getElementById('counter');
    var div = document.getElementsByTagName('XcounterX')[0];
    div.innerHTML = ball.innerHTML;
  };
</script>

2. jQuery

<script>
  $(document).ready(function(){
    $.ajax({
      url: "http://xxxx/counter.txt",
      success: function(data){
        $("#XcounterX").empty();
        $("#XcounterX").html(data);
      }
    });
  </script>

  <div id='XcounterX'></div>
Robiseb
  • 1,576
  • 2
  • 14
  • 17
  • Unfortunately, none of these options work. Is this possible at all? Both sites have same origin. One is (https://xxxx/counter.txt) and second is (https://xxxx/yyyy). I try to take result from https://xxxx/counter.txt and display it on https://xxxx/yyyy – Aleksander Pawłowski Nov 05 '16 at 11:53