Page 1 of 1

passing values between frames -> parsing error

Posted: Wed Nov 10, 2004 5:04 am
by jasongr
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: Select all

<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:

Code: Select all

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

Posted: Wed Nov 10, 2004 5:51 am
by josh
on the page that prints out the javascript do
$content = str_replace("'", "This_is_a_single_quote", $content)

Then on the page that prints out content do this
$content = str_replace("This_is_a_single_quote", "'", $content)


Kind of a "make shift" way to get this done but i use this method alot, it replaces the quote with some text then changes it back later... you might wanna use something like %%qt%% instead of This_is_a_single_quote or something like that

Posted: Wed Nov 10, 2004 5:54 am
by CoderGoblin
My understanding is that Style does not need the single quote...

Code: Select all

<span style="font-family: 'Arial, Helvetica, sans-serif'>Hello</span>
but you might run into problems if the string is

Code: Select all

<span style="font-family: Arial, Helvetica, sans-serif>O'Reilly</span>
In the above code it would be better to htmlspecialchars the "O'Reilly".

Remember you can use the escape character \ in both Javascript and PHP.

Posted: Wed Nov 10, 2004 6:05 am
by jasongr
there is a problem with this solution because it assumes I can run PHP on the recieving side

remember that the transfer is made in JavaScript after the page loads which means that any processing must be done in JavaScript

Posted: Wed Nov 10, 2004 6:28 am
by CoderGoblin
CoderGoblin wrote:Remember you can use the escape character \ in both Javascript and PHP.
or if the content is always the same structure why not call a javascript function on the parent passing in the content. Th function would build the structure and place the smaller content.

Posted: Wed Nov 10, 2004 6:37 am
by jasongr
I need to know how to cause the following string:

Code: Select all

<span style="font-family:'ariel'">
   test
</span>
to transform into the following:

Code: Select all

<span style="font-family:'ariel'">   test</span
I need to replace all newlines with empty string or something.
How can I do it in PHP?

Posted: Wed Nov 10, 2004 6:47 am
by CoderGoblin
$string=str_replace("\n","",$string);

Posted: Wed Nov 10, 2004 6:48 am
by jasongr
thanks that solved my problem