Adding an Image in HTML doc using JavaScript in Alfresco
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2014 08:29 PM
var url = "http://127.0.0.1:8081/share/proxy/alfresco/api/node/content/'+urlStr.substring(4);
I have to pass this as src attribute to an image:
var content = "";content += "<img src=\"url\">";
But this doesn't work.
I also tried inserting image using document.createElement("img"); and var img = new Image(); but javascript is not able to recognize the createElement() method or the Image() object.
Can anyone suggest how an image can be added to the HTML doc using Javascript in Alfresco?
- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2014 11:06 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2014 11:23 PM
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2014 12:43 AM
The below code is used to render image from javascript.
var imageUrl = Alfresco.constants.PROXY_URI+"api/node/content/workspace/SpacesStore/"+{UUID of image content}+"/"+{Name of the image};
<img src="'+imageUrl+'?a=true" width = "65px" height = "35px"/>
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2014 08:38 AM
var boxwidth = document.properties["sc:price"];content += "<body align=\"center\"><font face= \"Comic sans MS\">";content += "<b>Retail Price: </b>" + price + "<br><br>";content += "<img src=\"'+res+'?a=true\" width = \"65px\" height = \"35px\"/>";newFile.content = content;
So, I need to escape the double quotes while passing it to the content string.
I tried your code but still the image isn't getting displayed. Is my syntax wrong somewhere? I passed the url as you had mentioned.
I greatly appreciate your help.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2014 09:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2014 09:30 AM
content += "<img src=\"'+res+'\" width = \"65px\" height = \"35px\"/>";
Still, I am not able to see the image.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2014 10:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2014 10:39 AM
var urlStr = document.assocs["sc:relatedDocuments"][0].url;var res = "http://127.0.0.1:8081/share/proxy/alfresco/api/node/content/'+urlStr.substring(4);content += "<img src=\"'+res+'\" width = \"65px\" height = \"35px\"/>";
It works when I use it in link as:
var str = "View Image";var result = str.link(res);content += result+"<br><br>";
Thanks again for looking into it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2014 05:03 PM
http://127.0.0.1:8081/share/proxy/alfresco/api/node/content/workspace/SpacesStore/88265db1-371c-4ad2...
the GUID bit at the end will of course be different.
It doesn't look like that's what you will end up with but I may be wrong.
Also you are going to localhost on a non standard port for Alfresco so I assume your browser is running on the same machine as your Alfresco installation and the you have explicitly assigned alfresco to 8081 away from 8080.
