SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict jasongr's Avatar
    Join Date
    Jul 2004
    Location
    usa
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing values between frames -> parsing error

    Hello

    I have a window call A.html that contains an iframe called B.php

    B.php determines what its content should be in HTML and it holds that info in a PHP variable called $content

    That means that the value of $content is now something like:
    Code:
    <table border="2" cellspacing="0" width="100%">
      <tr>
        <td>
          <span style="font-family: 'Arial, Helvetica, sans-serif'>Hello</span>
        </td>
      </tr>
    </table>
    Note that the code contains both " and '

    Now in the iframe onload event I want to pass the content of the $content variable to the innerHTML value of some div in A.html

    I do the following:
    PHP Code:
    function onLoad() {
      var divElement = parent.document.getElementById('div');
      divElement.innerHTML = '<?php print $content?>';
    }
    Now note that the single ' that enclouses the value of the innerHTML. They interfere with the ' and " that are part of the content of $content

    How can I solve this problem and pass any arbitrary HTML content between pages by using JavaScript?

    regards
    Help would be appreciated

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wrong
    Code:
          <span style="font-family: 'Arial, Helvetica, sans-serif'>Hello</span>
    right
    Code:
          <span style="font-family: Arial, Helvetica, sans-serif">Hello</span>
    better use sessions to pass that big var
    cheers

  3. #3
    SitePoint Addict jasongr's Avatar
    Join Date
    Jul 2004
    Location
    usa
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I cannot use sessions because the variable is passed on the client side (remember? it is passed in the IFrame's onload event)

    I know realize that I have 2 problems:
    1) existance of ' and " inside the big string
    2) the formatting of the string forbids it from breaking lines

    I cannot have:
    Code:
    <span style="font-family: 'Arial, Helvetica, sans-serif'>
       Hello
    </span>
    I must have:
    <span style="font-family: 'Arial, Helvetica, sans-serif'>Hello</span>

    Is there a way to tell JavaScript to encode the string into a one line encoding with no ' or " and I will decode the string in JavaScript in A.html?

  4. #4
    SitePoint Addict jasongr's Avatar
    Join Date
    Jul 2004
    Location
    usa
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have 2 problems:
    1) the ' in the HTML content is corrupting the string
    2) The html content is broken into several lines

    I managed to solve problem #1 by escaping all the ' by \

    I still have the second problem which is better because this one could be solved using both PHP or JavaScript

    Here is what I do with the content:
    PHP Code:
    divElement.innerHTML = '<?php print $content?>';
    Problem 2 stems from the fact that the content of the $content variable may span over multiple lines like so:
    Code:
    <span style="font-family:'ariel'">
      test
    </span>
    which causes the assignment statement to have bad syntax.
    Is there a way to transform it into a single line while still maintaining a legal HTML?

    i.e. to transform it into:
    Code:
    <span style="font-family:'ariel'">test</span>

  5. #5
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Madison, WI
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just a side note, style="font-family: 'font'" is not proper css...get those ' out of there to make it correct (i.e. style="font-family: font;")

    if you wanted $content to all be one line (which shouldn't matter anyway), you could run
    PHP Code:
    $content=str_replace("\n",'',$content); 
    before you output the $content var in the javascript

  6. #6
    SitePoint Addict jasongr's Avatar
    Join Date
    Jul 2004
    Location
    usa
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks that did the trick


Bookmarks

Posting Permissions

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