473,237 Members | 1,374 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,237 software developers and data experts.

Help: Imbedded </script> within a document.write()

I am attempting to use document.write(pageVar) that displays a new html page
within a pop-up window and the popup is failing. Also note that pageVar is
a complete HTML page containing other java scripts.

Being a javascript newbie and after significant testing, I suspect that the
document.write fails after finding a </script> within pageVar.

Does a trick exist that enables one to slightly alter pageVar whereby
enabling document.write(pageVar) to display a complete HTML page that
contains other javascripts?

Thanks,
Mike.
Jul 20 '05 #1
6 12919
If I understand you correctly, then this is the same issue I encountered
last year, and I managed to work around it.

Write it in several parts,

response.write("<scr")
response.write("ipt>")

This is ugly and terrible, but it works.

Gets really messy when you've got vbscript writing javascript which is
writing html dynamically but... sometimes we have to play the cards we
are dealt.

I hope that helps you out.
Greg.

Mike Daniel wrote:
I am attempting to use document.write(pageVar) that displays a new html page
within a pop-up window and the popup is failing. Also note that pageVar is
a complete HTML page containing other java scripts.

Being a javascript newbie and after significant testing, I suspect that the
document.write fails after finding a </script> within pageVar.

Does a trick exist that enables one to slightly alter pageVar whereby
enabling document.write(pageVar) to display a complete HTML page that
contains other javascripts?

Thanks,
Mike.


Jul 20 '05 #2
"Mike Daniel" <ma****@cox.net> writes:
I am attempting to use document.write(pageVar) that displays a new html page
within a pop-up window and the popup is failing. Also note that pageVar is
a complete HTML page containing other java scripts.


When you have a script element, it starts at the <script ...> tag and
ends at the *first* occurence of "</" after that. In practice, most
browsers are less picky, and doesn't stop until the first occurence
of "</script>".

So, if you have:
<script type='text/javascript">
var foo = "</script>";
</script>
the script element ends prematurely.

The recommended solution is to write:
var foo = "<\/script>";
This escapes the forward slash, which doesn't matter in Javascript
strings, but seen from the HTML parser's perspective, there is no
longer a "</" too many.
In your case, you have a string containing HTML code to be written.
That code contains script tags. My guess is that one of these
script tags contain a document.write as well, and an HTML script
end tag.

So, whereever you define pageVar, you need to make sure that
when it is written to another page, it writes an escaped slash.

That is, if pageVar contains
' ... "</script>" .... '
(a string to be written on the second page), you must change it
to:
' ... "<\\/script>" ... '
The double backslash means that the string contains a backslash,
and that it is written correctly to the other page.

Good luck
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
In article <Bg%8b.54261$cj1.31898@fed1read06>, "Mike Daniel" <ma****@cox.net>
writes:
Being a javascript newbie and after significant testing, I suspect that the
document.write fails after finding a </script> within pageVar.

Does a trick exist that enables one to slightly alter pageVar whereby
enabling document.write(pageVar) to display a complete HTML page that
contains other javascripts?


Escape the / in the script tag:

document.write('<\/script>')

It is well known about by some, not by others.
--
Randy
Jul 20 '05 #4
Additional details:

The original HTML document is generated on a remote system via a servlet
requests. The servlet requests from the remote system a HTML pepared menu
and wraps the returned menu with XML, then the servlet requests from the
remote system a HTML constructed report and wraps it with report specific
XML. The same servlet concatenates the two documents together with
appropriate beginning and ending XML tags (then passes it back into Novell's
NPS/eXtend Directory portal servlet). The portal servlet then unwraps (I
think) the XML and sends the combinded HTML document to the browser. The
browser displays the menu on one window and (intentions are) the report is
supposed be displayed in a browser type popup window. The main window
contains the popup javascript. In the same document, the popup javascript
is called and (at this time) the entire HTML document has been inserted into
the <SCRIPT>...document.write("<HTML> ...<script>
....</script>...</HTML>")</script>, and can be seen via the browsers view
source. The pageVar referenced in the original request is this inserted
HTML document wrapped with double quotes. At this time, the HTML document
contains only single quotes as converted by servlet after receiving pageVar
from remote system. My thoughts are to eliminate web browser and javascript
confusion.

My thoughts at this time is to correct the report HTML document's script
immediately after the servlet receives it from the remote system. Now I am
having trouble coding the servlet to appropriately alter </servlet> to
<\\/servlet> due to Java escape code "conflict" originating within the
servlet. I was using pageVar.replaceAll("</script>","<\\/script>"); but
this becomes a <\/script> as seen in the view source. Now the report window
appears but no report data follows. If <\/script> replaces <\\/script>, the
java compiler complains.

What tricks can be used to replace "</script>" to look something
"<\/script>" within the java servlet?

Mike.

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:zn**********@hotpop.com...
"Mike Daniel" <ma****@cox.net> writes:
I am attempting to use document.write(pageVar) that displays a new html page within a pop-up window and the popup is failing. Also note that pageVar is a complete HTML page containing other java scripts.


When you have a script element, it starts at the <script ...> tag and
ends at the *first* occurence of "</" after that. In practice, most
browsers are less picky, and doesn't stop until the first occurence
of "</script>".

So, if you have:
<script type='text/javascript">
var foo = "</script>";
</script>
the script element ends prematurely.

The recommended solution is to write:
var foo = "<\/script>";
This escapes the forward slash, which doesn't matter in Javascript
strings, but seen from the HTML parser's perspective, there is no
longer a "</" too many.
In your case, you have a string containing HTML code to be written.
That code contains script tags. My guess is that one of these
script tags contain a document.write as well, and an HTML script
end tag.

So, whereever you define pageVar, you need to make sure that
when it is written to another page, it writes an escaped slash.

That is, if pageVar contains
' ... "</script>" .... '
(a string to be written on the second page), you must change it
to:
' ... "<\\/script>" ... '
The double backslash means that the string contains a backslash,
and that it is written correctly to the other page.

Good luck
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #5
> I am attempting to use document.write(pageVar) that displays a new html page
within a pop-up window and the popup is failing. Also note that pageVar is
a complete HTML page containing other java scripts.

Being a javascript newbie and after significant testing, I suspect that the
document.write fails after finding a </script> within pageVar.


Put a backslash in front of the slash.

document.write('<\/script>');

JavaScript will happily ignore the backslash, which is at the same time
preventing the browser's hopeless confusion.

jslint catches mistakes like these.

http://www.crockford.com/javascript/lint.html

Jul 20 '05 #6
JRS: In article <20***************************@mb-m28.aol.com>, seen in
news:comp.lang.javascript, HikksNotAtHome <hi************@aol.com>
posted at Sun, 14 Sep 2003 23:15:41 :-
In article <Bg%8b.54261$cj1.31898@fed1read06>, "Mike Daniel" <ma****@cox.net>
writes:
Being a javascript newbie and after significant testing, I suspect that the
document.write fails after finding a </script> within pageVar.

Does a trick exist that enables one to slightly alter pageVar whereby
enabling document.write(pageVar) to display a complete HTML page that
contains other javascripts?


Escape the / in the script tag:

document.write('<\/script>')

It is well known about by some, not by others.


In particular, IIRC, it is well known about by W3's free off-line HTML
tester TIDY.

Anyone who produces HTML for the WWW without checking it with something
like TIDY is, at best, an optimist.

http://www.w3.org/People/Raggett/tidy/
or http://tidy.sourceforge.net/

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Ken | last post by:
How do I force the text generated by a document.write command to wrap after a specified number of characters? Thanks for the help.
2
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of...
1
by: Kevin Potter | last post by:
We have an application that has been running on IIS4 and IIS5 for quite some time, without problem We're now migrating to IIS6 (windows/2003), and have run into a what might? be a Javascipt...
14
by: Eli | last post by:
I've got a script that I'm trying to debug which uses document.write() to place HTML within a page. In both IE6 and Firefox when I view source, I see only the script itself and not any HTML as...
7
by: Ignac Vucko | last post by:
Is writing a document *during* page load safe and supported for all 4th and 5th generation browsers? If not, can you show me a specific example/browser where it causes problems? <html> <head>...
12
by: Sean | last post by:
Hi, I have the following script: ----------------------------------------------------------------------------------- <script type="text/javaScript"> <!-- document.write('<div...
2
by: bissatch | last post by:
Hi, I am trying to use JavaScript to write a table column on a web page. The code is as follows: <html> <head> <script> function displaycount() {
11
by: Michael Powe | last post by:
How can I make an XHTML-compliant form of an expression in this format: document.write("<scr"+"ipt type='text/javascript' src='path/to/file.js'>"+"</scr"+"ipt>"); this turns out to be a...
3
by: e271828 | last post by:
I've got a way to get all of the source HTML for a given page by line and detect where certain attributes exist, and I would like to write the line of HTML code I've been working on into a new...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.