Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- document.write Syntax Problem in Remote Javascript


egomaniac - 5:28 pm on Nov 9, 2002 (gmt 0)


I want to display a text link using a remote javascript file, and I want the status bar at the bottom of the browser to display a custom message when the user mouses over the text link. My link works correctly in regular HTML page.

Example That Works Correctly:
<a href="http://www.some-other-domain.com/" onMouseover="window.status='Hello World'; return true;">Click This Text Link</a>

But when I turn this into a remote javascript file using document.write, the browser is unable to display the link.

Contents of Remote Javascript File:
document.write('<a href="http://www.some-other-domain.com/" onMouseover="window.status='Hello World'; return true;">Click This Text Link</a>');

I believe the problem is in the use of the single quotes around the custom message 'Hello World'. If you look closely, you'll notice that there is an opening quote for the document.write command just after the first parenthesis (' and there is a closing quote just before the last parenthesis '). The first single quote before 'Hello is prematurely and incorrectly closing the document.write statement, which results in a syntax error that the browser cannot interpret.

Does anyone know the proper syntax for the custom message 'Hello World' when using document.write in remote javascript file?
-egomaniac


Thread source:: http://www.webmasterworld.com/javascript/224.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com