View Full Version : Trying to have javascript withing javascript...

04-11-2003, 10:37 PM
My JS will use document.write to create an IFRAME in the page. I also want it to write in the HTML file that the IFRAME loads. I want it to write a <nobanner> tag. I don't want to have to put it in the source of the file myself. So, I tried to do this:
document.write('<iframe src="http://nhsforum.0catch.com/' + id + '.html" onLoad="javascript:document.write("<nobanner>")"></iframe>')

BUT, that does not work because of the double-nested " and '. So, I tried using " instead of ' and then it works and writes the javascript to the IFRAME, however it has a JS error when the IFRAME loads because you now have the tag:
<iframe src="BLAH" onLoad="javascript:document.write("<nobanner")">

Where it has " inside of ". I want a javascript to write to the page an IFRAME tag and also write to the source page of the IFRAME a <nobanner> tag. Is this possible? Because I think you would end up like double-nesting your quotes.
Goto http://nhsforum.0catch.com/articles/testsend.html and type 040903war in the box.

04-11-2003, 10:39 PM
I have no idea, I'm a PHP Guy, but try escaping the quotes:


Quiet Storm
04-12-2003, 12:31 AM
Unescape... and you're messing up your quotes.

Try this (copy&paste):

document.write('<iframe src="http://nhsforum.0catch.com/\' + id + \'.html"

04-12-2003, 09:53 PM
:thumbsup: It's been a while since I last used JS. I now remember how to exit quotes.That was right and everything except I want the quotes to be there where it says + id + so that it inserts a variables contents there.

document.write('<iframe src="http://nhsforum.0catch.com/articles/current/' + id + '.html" onLoad="javascript:document.write(\'<nobanner>\')"></iframe>')

So, I think that'll work. However when I try that, it returns no JS errors but it does not seem to be writing the <nobanner> to the page loaded in the iframe. So, the iframe page has a banner (the <nobanner> removes the banner ad on the page). So I think I have to assign my iframe a name. And then, I have to use:


I don't know if that works or not. Or maybe it's:

document.name.document.write ('<nobanner')


name.document.write ('<nobanner')

Any Ideas? :confused:


04-12-2003, 11:40 PM
I want a javascript to write to the page an IFRAME tag and also write to the source page of the IFRAME a <nobanner> tag. Is this possible?Nope. The 'source page' is a URL, which loads a complete HTML document into the iframe; you can't just add markup to it on-the-fly. If it's from another domain, you can't even script it ('same origin policy').

04-13-2003, 03:04 AM
Well, it is on the same domain. And, I still think it may be possible to assign the IFRAME a name and use a document.write or similar to write the tag to the page. See, this is for a school newspaper web site. So, I have many article pages and I don't want to have to manually insert the tag into every page. Plus if I can use this as a safeguard if I forgot to put the tag in an article page. I can currently save the RichText documents the writers give me as HTML files. But, Lotus won't allow me to add the tag when I save it. So, I'd have to add it to the page in notepad or Dreamweaver. That's a pain. I want the web site display page (that retrieves the article into an IFRAME) to automatically put the tag in the articles so the IFRAME doesn't have an ugly banner ad in it.

04-13-2003, 04:36 AM
document.write('<iframe src="http://nhsforum.0catch.com/' + id + '.html" onLoad="java script:document.write("<nobanner>")"></iframe>')

When nesting quotes within quotes you MUST:
* alternate between double and single quotes.
* Make sure the quotes are "matched" or paired properly. The JS statement has the quotes improperly matched.

Maybe it should look like this:

document.write('<iframe src="'http://nhsforum.0catch.com/' + id + '.html'" onLoad="java script:document.write('<nobanner>')"></iframe>')

04-14-2003, 11:31 PM
Sorry, but you can only use one set of " and one set of ' in a nested set. But, I already figured it out based on escaping quotes. I forgot you could put a \ before it to escape it's JS value. Thanks anyways.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum