Javascript: Defining img src with an absolute path - codesd.com
source link: https://www.codesd.com/item/javascript-defining-img-src-with-an-absolute-path.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Javascript: Defining img src with an absolute path
I am trying to manually set the img src to a path on the filesystem, and then I want to draw that image on a canvas. I am using:
var curr_canv = document.getElementById('c_main').getContext('2d');
var img = new Image();
img.width = 525;
img.height = 400;
img.src = "..\AAAA\BBBB\CCCC\myimage.jpg";
curr_canv.drawImage(img,0,0);
But nothing is drawn on the canvas after I do this. Any thoughts?
You need to set the path to an absolute path within your webserver.
Javascript in the browser has no access to any filesystem.
Related Articles
One way to replace a shortcut with an absolute path in linux
Python will not quit when called with an absolute path of cron or subshell
Switching background images with the absolute path of javascript forces
How do you modify img src with javascript depending on browser width?
Define img src from an input box with jQuery
Modification of MVC Razor Img src with javascript
Change IMG SRC with Javascript
Displaying the image with the absolute path in JSP
Angular 2 img src in a relative path
Changing img src with jQuery without loading the image several times?
change img src with fadein in jquery
Apache / PHP unable to run convert even when called with an absolute path
Asp includes with an absolute path
How to target img src with jQuery
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK