How to include "<script>" in a string ?

T

Tom de Neef

I have a second window for pop-ups.
It is used to display text generated by the calling code, rather than a
referenced html document.
To execute links in that text, some script code needs to be added to the
text. But I cannot get the script included.

function PopUp(txt)
{
var head = '<head>'+
'<script type="text/javascript"
src="wwRegels.js"></script>'+
'</head>'

secondWindow.document.write('<html>'+head+'<body>'+txt+'</body></html>')
secondWindow.document.close()
if (window.focus) { secondWindow.focus() }
}

Browsers (IE, FF) object to the line starting with '<script (unterminated
string literal) when loading the page. If I change "script" into "scrapt",
loading completes without rrors. The browser seems to refuse "<script" as
part of my string or I am blind to some mistake I've made. I have tried
backslashes here and there but to no avail. Is there a way around ?

TIA
Tom
 
T

Thomas 'PointedEars' Lahn

Tom said:
function PopUp(txt)
{
var head = '<head>'+
'<script type="text/javascript"
src="wwRegels.js"></script>'+
'</head>'

secondWindow.document.write('<html>'+head+'<body>'+txt+'</body></html>')
secondWindow.document.close()
if (window.focus) { secondWindow.focus() }
}

Browsers (IE, FF) object to the line starting with '<script (unterminated
string literal) when loading the page. If I change "script" into "scrapt",
loading completes without errors. The browser seems to refuse "<script" as
part of my string

They should not and AFAIK they do not.
or I am blind to some mistake I've made.

I see two probable possibilities for the observed behavior:

a) You use the code as posted in which case the string literal is indeed
not terminated (before the newline). Use string concatenation or a
joined array to work around that.

b) Because you have not escaped the ETAGO delimiter (`</') the script
element that this code is contained in ends prematurely. Use
`<\/', respectively.
I have tried backslashes here and there but to no avail.

A useless statement.
Is there a way around ?

Probably yes.


PointedEars
 
T

Tom de Neef

Thomas 'PointedEars' Lahn said:
They should not and AFAIK they do not.


I see two probable possibilities for the observed behavior:

a) You use the code as posted in which case the string literal is indeed
not terminated (before the newline). Use string concatenation or a
joined array to work around that.

b) Because you have not escaped the ETAGO delimiter (`</') the script
element that this code is contained in ends prematurely. Use
`<\/', respectively.

Thank you.
a) the new line in this post was not in the code that I mailed. Clearly that
was not the cause.
b) '</script>' -> '<\/script>' that solves it !

Tom
 
T

Thomas 'PointedEars' Lahn

Tom said:
Thank you.
a) the new line in this post was not in the code that I mailed.

Despite your using an application that is capable of sending e-mails, too,
you did not mail anything here.
Clearly that was not the cause.

Which should make clear to you that code should be posted in a fashion that
automatic line-break near 80 characters does not cause a change in its
meaning. Using spaces instead of tabs helps to achieve that, too.
b) '</script>' -> '<\/script>' that solves it !

I expected that, as it is not exactly a new "problem". Please search before
you post next time. And trim your quotes.

http://jibbering.com/faq/


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top