Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > How to include "<script>" in a string ?

Reply
Thread Tools

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

 
 
Tom de Neef
Guest
Posts: n/a
 
      02-24-2008
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


 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      02-24-2008
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
 
Reply With Quote
 
 
 
 
Tom de Neef
Guest
Posts: n/a
 
      02-24-2008
"Thomas 'PointedEars' Lahn" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      02-24-2008
Tom de Neef wrote:
> "Thomas 'PointedEars' Lahn" <(E-Mail Removed)> [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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
/* #include <someyhing.h> */ => include it or do not include it?That is the question .... Andreas Bogenberger C Programming 3 02-22-2008 10:53 AM
Re: the use of #include <a_file.h> v/s #include"a_file.cpp" Elie Nader C++ 1 11-28-2003 03:12 PM
Re: the use of #include <a_file.h> v/s #include"a_file.cpp" Rolf Magnus C++ 2 11-28-2003 12:26 PM
#include "bar" negates #include <string> ; how to fix? Danny Anderson C++ 5 08-15-2003 06:38 PM



Advertisments