Solved

php with embedded javascript outputs newlines on HTML tags?

Posted on 2013-11-30
6
399 Views
Last Modified: 2013-12-01
I have a php page with JavaScript to be used on a wordpress page,but when the page is generated all <div> <p> etc. appends new lines. Example :

Test.php ->

<script type="text/javascript">
alert('hello<div>world</div>');
</script>
When I view-source there is new lines on each html-tags : <div><p> - which breaks the JavaScript syntax

I tried to remove filter wpautop on content, but no go :(

Thanks
php-newlines.PNG
0
Comment
Question by:Eidos_IT
6 Comments
 
LVL 15

Expert Comment

by:eemit
ID: 39687676
You should use Element.html like this:
<div id="my-pageid">
<div id="id-to-insert-html">
</div>

- - -

<script>
var el = document.getElementById('id-to-insert-html');
el.html = '<div><p>hello world</p></div>';
</script>
0
 
LVL 2

Expert Comment

by:goubun
ID: 39687782
I think that the problem is because you are inserting the code in visual editor mode and you have to insert that only in text mode, You can change the mode of the editor in the right-top tab in the entry editor.
0
 

Author Comment

by:Eidos_IT
ID: 39687805
The issue is not the code it self, the alert stuff is just an example and not relevant.

The reason is that I am using a plugin for wordpress that just dont work, so I found out that the javascript is broken due to the line breaks and <p>.

I can't see this as an editor issue, the line break is happening in the middle of a string, and I am using clean nano on linux.

This is clearly a wordpress issue/feature, because if I run the page as a normal php page on apache2 there is no issues.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 13

Accepted Solution

by:
duncanb7 earned 500 total points
ID: 39687969
take a look at this , and just try it on link-1 replace img tag by your tag or *  in preg_replace for similar issue as yours

link-1 http://css-tricks.com/snippets/wordpress/remove-paragraph-tags-from-around-images/

linke-2 take a look if have time
http://sww.co.nz/solution-to-wordpress-adding-br-and-p-tags-around-shortcodes/

Hope it will give your some hint

Duncan
0
 

Author Comment

by:Eidos_IT
ID: 39688752
Duncan this is clearly in the right direction - THX
0
 
LVL 13

Expert Comment

by:duncanb7
ID: 39688766
Thanks for your pt

Hava a nice day

Duncan
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now