www.webdeveloper.com
Results 1 to 12 of 12

Thread: Pass HTML through JSON

  1. #1
    Join Date
    Dec 2013
    Posts
    7

    Pass HTML through JSON

    Hi Fellas,

    my problem is following that I have JSON strings which include HTML code, but if I print out those strings they don't interpret the HTML code, instead it is like it was in a <pre> tag. http://chris1904.webege.com/test2.html you can analyse my problem right there. How do I get to it to work so HTML is interpreted when using it in JSON strings?

    Chris

  2. #2
    Join Date
    Oct 2013
    Posts
    267
    "Google Chrome could not connect to chris1904.webege.com"

  3. #3
    Join Date
    Dec 2013
    Posts
    7
    That's weird. It works on my end on chrome, mozilla, and safari.

  4. #4
    Join Date
    Dec 2013
    Posts
    21
    I can see it in Safari. Are you talking about the "Jane Parker" message?

    Text: "<iframe width=\"420\" height=\"315\" src=\"//www.youtube.com/embed/NiXbRBS5Z58\" frameborder=\"0\" allowfullscreen></iframe>",

  5. #5
    Join Date
    Dec 2013
    Posts
    7
    Exactly, I want this iframe to actually be produced and not just show up the code . Sorry for not articulating understandably

  6. #6
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,633
    this is Usher-Yeah )) but youtube doesn't let watching it from another site
    Last edited by Padonak; 01-06-2014 at 08:30 PM.
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  7. #7
    Join Date
    Dec 2013
    Posts
    7
    Well, even then HTML is not interpreted and I was just wondering how I can get that fixed. I just used that video as an example

  8. #8
    Join Date
    Dec 2013
    Posts
    21
    Well, I am too new to this stuff to really say for sure but it seems like your "JSON" text is being interpreted as just that...text. You need to parse it perhaps for the browser to know you actually want an inline frame. How to do that? "eval(Text)" maybe?

  9. #9
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,633
    i would try looking for the answer in kendo documentation or ask kendo users
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  10. #10
    Join Date
    Mar 2009
    Posts
    430
    Try putting an empty DIV element in your HTML and then set its innerHTML property to that of the string.

  11. #11
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,252
    it's always possible to detect or remove the tags with something like this :

    Code:
    // to replace the text with something
    if (/<?\/[^>]+>/g.test(text)) {/* text= ... change the text */}
    // to remove the tags 
    text=text.replace(/<?\/[^>]+>/g,'');
    if (!text) text="No text  to display !"

  12. #12
    Join Date
    Mar 2012
    Posts
    202
    Your problem lies in this piece of code:

    Code:
    <script type="script/x-kendo-template" id="inboxItem">
        <h3 class="time">#: Time#</h3><h3>#: From #</h3>
        <h2>#: Subject#</h2>
        <p><div id="myAnchor">#: Text#</div></p>
    </script>
    Please see the documentation here.

    You could make an easy fix for it by making the following change:

    Code:
    <script type="script/x-kendo-template" id="inboxItem">
        <h3 class="time">#: Time#</h3><h3>#: From #</h3>
        <h2>#: Subject#</h2>
        <p><div id="myAnchor">#= Text#</div></p>
    </script>
    But that would leave a possible XSS vulnerability open. I would suggest doing the following:

    Code:
    <script type="script/x-kendo-template" id="inboxItem">
        <h3 class="time">#: Time#</h3><h3>#: From #</h3>
        <h2>#: Subject#</h2>
        <p><div id="myAnchor">#: Text##= HTML#</div></p>
    </script>
    Then just add an HTML variable to your JSON object solely for rendering raw HTML data.

    Had to do a little bit of research on this as I have absolutely no experience with this kendo framework. Hope it helps!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles