0

I have a remote file that contains a javascript code that needs to be executed, I'm interested to get its result from another page (that is on a different domain).

Remote Page :

    <script>
   var height = somevalue that I get using a lot of calculations that can be done only from that remote page;
    document.write(height);
    </script>

My Page :

<script>
jQuery.ajax({
     type: "GET",
     url: RemotePage,
     success: function(msg){
         alert(msg);
      }
});
</script>

Expected Result :

Height Value

Result :

    <script>
       var height = somevalue that I get using a lot of calculations that can be done only from that remote page;
    document.write(height);
    </script>

Clearly here the code is returned back and not executed, anyway to have the javascript executed, and then have the result returned? I have already tried setting the dataType : script on the AJAX settings, however this only takes the code and executes it on the current page, which results in an undefined result. Any way to achieve this goal?

Santosh Ram Kunjir
  • 1,074
  • 1
  • 12
  • 23
Faouzi FJTech
  • 981
  • 3
  • 13
  • 27
  • What do you think you are gaining by moving the code to a remote page? Why not just create a different JS script file? Reason I say this is because the code is going to be run via the user's client...the server won't be handling any computation. – Nick Delaney Mar 21 '16 at 17:40
  • @NickDelaney because the only way to get the data I need is through that remote page, it has to do with iframes, and therefore that js code can only run on the remote page so that I can get the right value I need. Having it elsewhere will just not work. – Faouzi FJTech Mar 21 '16 at 17:44
  • So are you trying to set the height of stuff within your iframe? If so then have the parent page do the calculations, and pass the variables via url params to the page within the iframe.. – Nick Delaney Mar 21 '16 at 17:46
  • @NickDelaney Yes exactly ! something close to that, I take first the parametres from the the child by making an AJAX call to the remote page which returns the height, then the iframe gets resized to that height, however the use case of this problem is not limited to that only, I would need a solution to resolve the javascript being executed on remote call since its a generic problem that may raise in a lot of other scenarios. – Faouzi FJTech Mar 21 '16 at 17:54
  • Checkout this post... http://stackoverflow.com/questions/251420/invoking-javascript-code-in-an-iframe-from-the-parent-page – Nick Delaney Mar 21 '16 at 17:58
  • @NickDelaney thank you for the link but thats for same domain iframes, and this also doesn't resolve the problem above, which is executing a javascript over a remote page whether it is or not iframe. – Faouzi FJTech Mar 21 '16 at 18:15

0 Answers0