Adding an Image in HTML doc using JavaScript in Alfresco
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2014 08:29 PM
I have an image url defined in my javascript code as:
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:
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?
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:
- Labels:
-
Archive
16 REPLIES 16
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2014 05:23 PM
The url path is correct as I could make a hyperlink with it and that works fine. My port is 8081 configured as I am running using the alfresco development environment. I think there is some issue with passing a string to JavaScript. It takes the string literally rather than replacing it with the actual contents of the string. Also, I tried creating img tag using document.createElement("img"); but the error log says cannot find createElement(). Any suggestions on a workaround this problem. Thanks a lot!

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2014 02:29 AM
I am not sure if I have understood correctly or not but as per my understanding if you are facing some problem to render image with javascript then I had same requirement to display image in div element from javascript and I have used in same way as I mentioned like,
var imageUrl = Alfresco.constants.PROXY_URI+"api/node/content/workspace/SpacesStore/"+{UUID of image content}+"/"+{Name of the image};
elCell.innerHTML = '<img src="'+imageUrl+'" width = "65px" height = "35px"/>';
Hope this helps.
var imageUrl = Alfresco.constants.PROXY_URI+"api/node/content/workspace/SpacesStore/"+{UUID of image content}+"/"+{Name of the image};
elCell.innerHTML = '<img src="'+imageUrl+'" width = "65px" height = "35px"/>';
Hope this helps.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2014 07:05 AM
Should
not be
"<img src=\"'+res+'\" width = \"65px\" height = \"35px\"/>";
not be
"<img src=\"+res+\" width = \"65px\" height = \"35px\"/>";
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2014 08:24 AM
Hi Aadit when I use innerHTML() and getElementById() function, I get an error saying, cannot recognize those functions. Most of the normal javascript functions won't work. Are there any settings to enable them in Alfresco?
Hi Bob, I had tried that too but still no luck.
Thanks!
Hi Bob, I had tried that too but still no luck.
Thanks!

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2014 12:22 AM
I think you are not coding in client side JS file.
You are writing these code stuff in one of the webscript JS file OR Action JS file??
You are writing these code stuff in one of the webscript JS file OR Action JS file??
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2014 08:14 AM
Hi Aadit, sorry but I don't understand you. I am writing this javascript file in the Script folder of Data Dictionary and executing it using a rule on one of my folders. I wanted to invoke it using a simple rule so didn't use webscript but directly executing JavaScript. Thanks again for your time and looking into this.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2014 11:29 AM
Finally, writing it this way worked for me:
'<img src=\"'+res+'\" width = \"150px\" height = \"100px\" >'
