What if you did something like this?
<a href="whatever.htm" target="main" onClick="DoWhatever()">Hello</a>
If you're document.writing it would probably look like
<script language="javascript">
var contentxes = "<a href='whatever.htm' target='main' onClick='DoWhatever()'>Hello</a>"
document.write(contentxes)
</script>
Or am I completely missing what you're trying to do?