Many developers will tell you that document.write()
is evil. I tend to agree with Peter Bailey's response that it is just easy to grossly misuse it.
At any rate, your script started out reasonably safe, but then Rocket Loader got a hold of it and decided to try and run it later, after the page had loaded. It's supposed to be able to "safely run any JavaScript code after window.onload", which implies that it modifies your script to be safe to run. You can't safely execute document.write()
after window.onload
.
Whatever Rocket Loader is doing, it's breaking your code, because when run as real JavaScript and not "RocketScript", it works just fine. So, you can either edit your script to be "safe", or disable RocketScript. A safer way to write your code would be to build the nodes dynamically. Your page already uses jQuery, so this sample code does as well:
$(function(){
var nbsp = "\xA0";
$("[data-tags]").each(function(){
var el = $(this);
var tags = el.data("tags").split(",");
for (var i = 0; i < tags.length; i++) {
var tag = $("<span>");
tag.addClass("label label-strong");
tag.text(tags[i]);
el.append(tag, nbsp);
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<div class="pull-right" data-tags="Factions,Minigames"></div>