0

Use JavaScript to Create img

Hi,

I'm using JavaScript to create a person's thumbnail.
CODE
var sThumb = '<img src="' + oPerson.getField(opensocial.Person.Field.THUMBNAIL_URL) + '">';


But it failed with the following error message:
CODE
stdin:31:         var sThumb = '<img + oPerson.getField(opensocial.Person.Field.THUMBNAIL_URL) + '">'; 
^^^^^^^
FATAL_ERROR: stdin:31+89 - 32+1: Unclosed string


It seems caja would filter out all the src attributes?

by
2 Replies
  • Hi josephj,

    I noticed that issue as well when I was playing with some sample code. What I did to get around this was to split up src like so:

    CODE
    var sThumb = '<img s' + 'rc="' + oPerson.getField(opensocial.Person.Field.THUMBNAIL_URL) + '">';


    Let me know if that doesn't work for you and we'll give it another shot. Caja is still in the process of being tweaked so that the development process is as easy as possible. You may run into issues like this in the future and if you do please feel free to post messages here and we'll address the problems as they arise.

    Jonathan LeBlanc
    Senior Software Engineer
    Yahoo! Developer Network

    QUOTE (啊嗚~ @ Nov 4 2008, 09:04 PM) <{POST_SNAPBACK}>
    Hi,

    I'm using JavaScript to create a person's thumbnail.
    CODE
    var sThumb = '<img src="' + oPerson.getField(opensocial.Person.Field.THUMBNAIL_URL) + '">';


    But it failed with the following error message:
    CODE
    stdin:31:         var sThumb = '<img + oPerson.getField(opensocial.Person.Field.THUMBNAIL_URL) + '">'; 
    ^^^^^^^
    FATAL_ERROR: stdin:31+89 - 32+1: Unclosed string


    It seems caja would filter out all the src attributes?
    0
  • Hi Jonathan,

    Thanks, it works.

    Yep, I will be glad to share my problems here ;)josephj
    0
  • I was having similar issues, and this post helped me fix my problem with the <img> tag.

    However, there seems to be lots of other issues with Caja. for example, i'm trying to link to a CSS style sheet and I get a parse error with the code:

    CODE
    <link rel="stylesheet" type="text/css" href="http://www.experienceproject.com/style.css"/>


    Or, if I try to use inline styles instead of a CSS my content does not render.

    Thanks.
    0
  • Hi DolamiteM,

    Yes, Caja is still very much a work in progress. We have open tickets for a lot of the issues you are experiencing and will be looking at all of them to see if there is a viable method for allowing the functionality without compromising the security of the platform.

    As far as CSS is concerned, style blocks currently do get stripped by the client-side sanitizer (http://developer.yahoo.com/yap/guide/what-are-cajas-limitations.html). We have had luck with using inline style's within the node's themselves (e.g. <div style="...">) so if you're running into issues with that if you could provide samples of what is going wrong we can give you a hand.

    Jonathan LeBlanc
    Senior Software Engineer
    Yahoo! Developer Network

    QUOTE (DolamiteM @ Feb 9 2009, 08:17 PM) <{POST_SNAPBACK}>
    I was having similar issues, and this post helped me fix my problem with the <img> tag.

    However, there seems to be lots of other issues with Caja. for example, i'm trying to link to a CSS style sheet and I get a parse error with the code:

    CODE
    <link rel="stylesheet" type="text/css" href="http://www.experienceproject.com/style.css"/>


    Or, if I try to use inline styles instead of a CSS my content does not render.

    Thanks.
    0

Recent Posts

in YAP