/    Sign up×
Community /Pin to ProfileBookmark

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>
[/code]

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=php]
function onLoad() {
var divElement = parent.document.getElementById(‘div’);
divElement.innerHTML = ‘<?php print $content; ?>’;
}
[/code]

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

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@David_HarrisonNov 10.2004 — You would have to replace all ' with ' with PHP and then pass it to the JavaScript.
Copy linkTweet thisAlerts:
@jasongrauthorNov 10.2004 — I have 2 problems:

1) the ' in the HTML content is corrupting the string

2) The html content is broken into several lines


I tried it and your solution solved problem #1

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:
[code=php]
divElement.innerHTML = '<?php print $content; ?>';
[/code]


Problem 2 stems from the fact that the content of the $content variable may span over multiple lines like so:
<i>
</i>&lt;span style="font-family:'ariel'"&gt;
test
&lt;/span&gt;

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:
<i>
</i>&lt;span style="font-family:'ariel'"&gt;test&lt;/span&gt;
Copy linkTweet thisAlerts:
@David_HarrisonNov 10.2004 — So just replace all new lines with nothing. n is the PHP code for a new line I think.
Copy linkTweet thisAlerts:
@jasongrauthorNov 12.2004 — thanks

that did the trick

I had to perform the following search and replace:

'n' to ' '

't' to ' '

'rn' to ' '

I also escaped every ' with

once again, thanks for the tips
Copy linkTweet thisAlerts:
@David_HarrisonNov 12.2004 — Happy to help. ?
×

Success!

Help @jasongr spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...