Tuesday, January 31, 2006

how to use javascript in script src attribute

Recently I faced a strange problem in javascript, I wanted to pass window.location.href in javascript src tag, but In javascript following holds true

Following is the quick hack which can be used for it

<script type='text/javascript'>
var pid = encodeURIComponent(window.location.href);
var jis='http://somehost&u='+pid;
document.writeln("<script type='text\/javascript' src="+jis+"><\/script>");
</script>

No comments: