?
Solved

document.write errors

Posted on 2007-11-27
4
Medium Priority
?
551 Views
Last Modified: 2010-04-21
Hi all,

I am using a simple script to output some html which is pretty straightforward as shown below.


(This works)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Pragma" content="no-cache">
<title>mag</title>
<script type=text/javascript language=javascript>
 
function window_onload() {
var txt="";
txt=txt+"<html><body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0' bgcolor='#999999'>";
txt=txt+"<object id=mag codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' height='100%' width='100%' align=left classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'>";
txt=txt+"<param name='movie' value='test.swf' />";
txt=txt+"<param name='quality' value='high' />";
txt=txt+"<param name='scale' value='noscale' />";
txt=txt+"<param name='bgcolor' value='#999999' />";
txt=txt+"<embed src='test.swf' quality='high' scale='noscale' bgcolor='#999999' width='100%' height='100%' name='mag' align='top' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
txt=txt+"</object>";
txt=txt+"</body></html>";
 
document.write(txt);
 
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#999999" LANGUAGE=javascript onresize="return window_onresize()" onload="return window_onload()">
</body>
</html>
 
But I need to add a refrence to javascript in the output but if I add this one line it brings up an error.
txt=txt+"<script type=text/javascript language=javascript src='popwin.js'></script>";
 
(The full function that returns the error. Im just outputing the text of the script reference.  I have no double quotes in the string)
function window_onload() {
var txt="";
txt=txt+"<html><body leftmargin='0' topmargin='0' marginwidth='0' marginheight='0' bgcolor='#999999'>";
txt=txt+"<script type='text/javascript' language='javascript' src='popwin.js'></script>";
txt=txt+"<object id=mag codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' height='100%' width='100%' align=left classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'>";
txt=txt+"<param name='movie' value='mag.swf' />";
txt=txt+"<param name='quality' value='high' />";
txt=txt+"<param name='scale' value='noscale' />";
txt=txt+"<param name='bgcolor' value='#999999' />";
txt=txt+"<embed src='test.swf' quality='high' scale='noscale' bgcolor='#999999' width='100%' height='100%' name='mag' align='top' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
txt=txt+"</object>";
txt=txt+"</body></html>";
 
document.write(txt);
 
}

Open in new window

0
Comment
Question by:binovpd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 200 total points
ID: 20362149
binovpd,

You have to split script tags and escape the closing slash when "writing" that line.

txt=txt+"<scr" + "ipt type=text/javascript language=javascript src='popwin.js'><\/scr" + "ipt>";

Let me know if you have any questions or need more information.

b0lsc0tt
0
 

Author Closing Comment

by:binovpd
ID: 31411318
Thank you I knew it was something that simple geez.
0
 

Author Comment

by:binovpd
ID: 20362173
Thanks b0lsc0tt,

I knew it was something that simple Geez.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20362250
Your welcome! :D  I'm glad I could help.  Thanks for the grade, the points and the fun question.

bol
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question