Entry
How do I use the javascript comment operator, //, in a string constant containing a url, http://...
Jun 12th, 2002 19:14
Jean-Bernard Valentaten, David Carr,
Your question is not quite clear, but I'll try to answer it anyway.
First we need to clarify things. Basically '//' and '/*...*/' are no
operators (they don't operate anything). They're just sequencess
telling the parser to ignore whatever comes after (or between them).
Since the parser won't parse the content of a string variable unless
you use it in an eval() statement, any double-slash (or '/*...*/') that
is contained in such a variable is "safe" (it will stay where it is).
Now one might say "What about escape-sequences, aren't they parsed?"
Yes they are, but they aren't parsed by the interpreter, but by the
methods (e.g. write(), alert(), ...).
Q: "Will the methods try to ignore comment-sequences?"
A: No they won't, except for eval(), because eval() starts an instance
of the interpreter, passing it the content of a variable to be parsed.
So the following line is correct javascript-code and won't cause any
problems:
var myURL = "http://www.riseofdarkness.de";
alert(myURL);
window.location.href = myURL;
This will assign the URL to myURL, display myURL and then load the page
at he content of myURL.
HTH,
Jean