Inserting extensive HTML in the middle of a JS function

Discussion in 'JavaScript' started by Submerged, Jul 22, 2008.

  1. #1
    I'm working on a function for a page that (simplified) looks like this:
    <script language="javascript" type="text/javascript"> 
    if (parent.frames.length != 0) 
    {
    document.write("Loaded in frames!")
    }
    </script>
    PHP:
    My question is somewhat odd. Basically, is there a way to insert a larger amount of HTML output (instead of just "Loaded in frames!" or "Not loaded in frames!") within the function that doesn't rely on document.write()?

    An analogy in PHP would be something like this:
    <?
    $var = 1;
    if ($var == 1)
    {
    ?>
    Hi there mom!
    <?
    }
    PHP:
    This echoes the HTML inside the function if and only if the "if" statement is met, but isn't forced to use echo() or print() or any such PHP function to do it.

    It's probably something easy, I'm just not that good at JS yet. Thanks for the help!

    -Alex
     
    Submerged, Jul 22, 2008 IP
  2. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Sorry to disappoint you but there's no other way. php files are parsed and everything outside the <? ?> tags is echoed to the browser (well, actually not everything, cause as you said your code will execute only if the if is true), but in js you have to explicitly tell the script where you want it to write. There are other possibilities, but document.write() is the easiest one in that case.
     
    xlcho, Jul 23, 2008 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    I guess I'd put all HTML in a hidden DIV, and tell Javascript to make this DIV visible, based on your condition.
     
    nico_swd, Jul 23, 2008 IP
  4. Submerged

    Submerged Active Member

    Messages:
    132
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    Is there anything like the EOT function of PHP in JS, so it wouldn't be dependent on quotes that might get broken in the HTML?
     
    Submerged, Jul 23, 2008 IP