I want to use this script on a conditional statement, hence why i thought of echoing it out in the first place.
echo "<script type='text/javascript'>
window.onload = function() {
if(!window.location.hash) {
window.location = window.location + '#loaded';
window.location.reload();
}
}
</script>";