Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Apr 2003
    Location
    Gainesville, GA
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Trying to have javascript withing javascript...

    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.
    ---Jacob
    Last edited by coolnetdude; 04-11-2003 at 10:40 PM.

  • #2
    New Coder
    Join Date
    Apr 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have no idea, I'm a PHP Guy, but try escaping the quotes:

    \"
    or
    \'

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Beyond Lament
    Posts
    424
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Unescape... and you're messing up your quotes.

    Try this (copy&paste):


    document.write('<iframe src="http://nhsforum.0catch.com/\' + id + \'.html"
    onLoad="javascript&#58;document.write(\'<nobanner>\')"></iframe>')
    Quíet Storm Designs ~ Art is not what you see, but what you make others see.
    · the Storms· || ·Ultraviolent Winter· || ·Was Einstein Wrong?· || ·It´s About Time!·

  • #4
    New to the CF scene
    Join Date
    Apr 2003
    Location
    Gainesville, GA
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb It's been a while

    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:

    document.name.write('<nobanner')

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

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

    Or:

    name.document.write ('<nobanner')

    Any Ideas?

    --Jacob

  • #5
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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').

  • #6
    New to the CF scene
    Join Date
    Apr 2003
    Location
    Gainesville, GA
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    Code:
     document.write('<iframe src="'http://nhsforum.0catch.com/' + id + '.html'" onLoad="java script:document.write('<nobanner>')"></iframe>')

  • #8
    New to the CF scene
    Join Date
    Apr 2003
    Location
    Gainesville, GA
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •