views:

58

answers:

2

I have a URL that generates a document.write method that inserts another JS.

Example:

http://domain.com/scriptONE.js

Generates

document.write('http://domain.com/scriptTWO.js');

How can I use jQuery to insert the second document.write to a div not an iFrame - so that my div contains only the output from this file

http://domain.com/scriptTWO.js
A: 

Try this:

$.get("http://domain.com/scriptTWO.js", function(data){
    $("#divObjectId").html($("#divObjectId").html()+data);
});

I think that I understand your question, if not is this what you want to do, please tell me better what you want to do.

Cesar
$.get won't work in his case as the js returns document.write(<script>script.js</script>);
Eeyore
@Eeyore Ok, but do you have a js file that includes another js file? Because you can use the $.ajax with parameter dataType: "script". More information on http://docs.jquery.com/Specifying_the_Data_Type_for_AJAX_Requests
Cesar
I will give it a try.
Eeyore
A: 

I think you need writeCapture.js (full disclosure: I'm the author.) The usage in your case would be:

$('#myDiv').writeCapture().html('<script type="text/javascript" src="http://domain.com/scriptONE.js"&gt; </script>');

And that's all there is to it. The plugin will take care of loading the other script and capturing the output and inserting it into the div.

noah