If you are using pure JavaScript, you could use this:
var body = document.body;
body.innerHTML += 'Whatever you want to append.';
题
Is it possible to append a whole code block using appendChild? This is what I want to append:
<script type="text/javascript" src="some.js"></script>
<!--[if lt IE 8]>
<link rel="stylesheet" type="text/css" href="styles-ie.css" media="all" />
<![endif]-->
<!--[if lt IE 7]>
<script type="text/javascript" src="85d6d1c5f8f9c87ae016eae0ee6994c7.js"></script>
<![endif]-->
I guess I cant append it using appendChild?
解决方案
If you are using pure JavaScript, you could use this:
var body = document.body;
body.innerHTML += 'Whatever you want to append.';
其他提示
function addLABjs(callback) {
var script = document.createElement("script");
script.setAttribute("src", "YourOtherScript.js");
script.addEventListener('load', function () {
var script = document.createElement("script");
script.textContent = "(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
// the guts of this userscript
function main() {
$LAB.script("YourOtherScript.js").wait()
.script("YourOtherScript.js")
.script("YourOtherScript.js").wait();
$(document).ready(function () {
});
}
addLABjs(main);