Welcome to WebmasterWorld Guest from 54.221.87.97

Forum Moderators: open

Message Too Old, No Replies

Why do I an error with this JavaScript?

script error: unterminated string constant

     

mckcd

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

10+ Year Member



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>
<\/frameset>
<\/frameset>')
//-->
</script>

DrDoc

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

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



parent.document.URL should probably be location.href

txbakers

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

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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> ";

etc.

then, it's as simple as:

document.write(pg);

and you won't get those unterminated string errors.

mckcd

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

10+ Year Member



Can't make that work either. :(

HocusPocus

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

10+ Year Member



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-
javascript:
in the location bar. This will pop-up a console which may help track down where the error is.

mckcd

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

10+ Year Member



Do I add (+) to pg for each line?
ie:
pg =
pg + =
pg ++ =
etc.

txbakers

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

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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.

mckcd

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

10+ Year Member



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

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

HocusPocus

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

10+ Year Member



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

BlobFisk

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

WebmasterWorld Senior Member blobfisk is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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!

mckcd

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

10+ Year Member



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.

mckcd

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

10+ Year Member



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

Thanks everyone, for all the help. :)