homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Why do I an error with this JavaScript?
script error: unterminated string constant

 12:00 am on Apr 15, 2003 (gmt 0)

I recently tried a generic JScript I got from this forum.
Not knowing JavaScript very well I am really thrown by the error.


<script language="JavaScript" type="text/javascript">
origURL = parent.document.URL
contentURL = origURL.substring(origURL.indexof('?')+1, origURL.length)

document.write('<frameset rows="117,*" frameborder="0" border="0" framespacing="0">
<frame name="top" src="top_frame_content.html" scrolling="no"
marginheight="0" marginwidth="0" noresize>
<frameset cols="141,*" frameborder="0" border="0" framespacing="0">
<frame name="nav" src="left_frame_content.html" scrolling="no"
marginheight="0" marginwidth="0" noresize >
<frame name="content" src="'+contentURL+'" scrolling="auto"
marginheight="0" marginwidth="0" noresize>



 12:18 am on Apr 15, 2003 (gmt 0)

parent.document.URL should probably be location.href


 12:45 am on Apr 15, 2003 (gmt 0)

It's because you have line breaks.

You start the document.write with a single quote (not a good idea BTW - use double quotes here and single quotes for the inside stuff).

Then, you use line breaks for each of the next lines. You can't do that in javascript.

Create a string variable:
var pg = "";
then, concatenate all your code with +

pg = "<frameset rows='117,*' frameborder='0' border='0' framespacing='0'>";
pg += "<frame name='top' src='top_frame_content.html' scrolling='no'
marginheight='0' marginwidth='0' noresize> ";


then, it's as simple as:


and you won't get those unterminated string errors.


 9:36 pm on Apr 15, 2003 (gmt 0)

Can't make that work either. :(


 8:40 am on Apr 16, 2003 (gmt 0)

If you do-

origURL = location.href +"";
contentURL = origURL.substring(origURL.indexOf('?')+1, origURL.length)

and get rid of the newlines in your document.write as txbak suggests, it'll work. Just tested it.

If you are getting nowhere, use mozilla or netscape 4 browsers to test. Open your document in the browser and type-
in the location bar. This will pop-up a console which may help track down where the error is.


 7:57 pm on Apr 16, 2003 (gmt 0)

Do I add (+) to pg for each line?
pg =
pg + =
pg ++ =


 8:08 pm on Apr 16, 2003 (gmt 0)

pg =
pg + =
pg ++ =

There is no space after the plus sign. It is an operator symbol in javascript and java:

pg += whatever

appends the whatever to the existing value of pg.
pg += whatever 1
pg += whatever 2
pg += whatever 3, etc.


 11:50 pm on Apr 16, 2003 (gmt 0)

I think I'm getting closer but I get a new error for origURL

"object doesn't support it's property or method"


 8:39 am on Apr 17, 2003 (gmt 0)

Paste the script so far, and I'm sure someone will suss.


 9:48 am on Apr 17, 2003 (gmt 0)

In your script decleration you use both the language and type decleration - you should only use the type="text/javascript" decleration - the language attribute is deprecated:

<script type="text/javascript">

I've seen using both cause problems with scripts before... although, since you're getting a specific error, I doubt that this will help, other than to make your code standards compliant!


 2:24 pm on Apr 17, 2003 (gmt 0)

Hey Hocus

I just noticed that you put indexOf with a capital "O".

No more errors, but:

Opening a page in IE6 opens the master frameset but doesn't force the page into it. "page could not be found"
It works in N4 though.


 4:07 pm on Apr 17, 2003 (gmt 0)

Actually I uploaded the pages and they work fine even in IE6 just not locally on my PC.

Thanks everyone, for all the help. :)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved