开发者

Multiple document.write from external scripts

I have a URL that generates a document.writ开发者_如何转开发e 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


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.


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"> </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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜