Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   How to include "<script>" in a string ? (http://www.velocityreviews.com/forums/t934815-how-to-include-script-in-a-string.html)

Tom de Neef 02-24-2008 02:31 PM

How to include "<script>" in a string ?
 
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



Thomas 'PointedEars' Lahn 02-24-2008 02:46 PM

Re: How to include "<script>" in a string ?
 
Tom de Neef wrote:
> 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
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann

Tom de Neef 02-24-2008 03:41 PM

Re: How to include "<script>" in a string ?
 
"Thomas 'PointedEars' Lahn" <PointedEars@web.de> schreef in bericht
news:47C18333.8020105@PointedEars.de...
> Tom de Neef wrote:
>> 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.
>


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



Thomas 'PointedEars' Lahn 02-24-2008 04:05 PM

Re: How to include "<script>" in a string ?
 
Tom de Neef wrote:
> "Thomas 'PointedEars' Lahn" <PointedEars@web.de> [wrote:]
>> 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.


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
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee


All times are GMT. The time now is 07:15 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57