3

Javascript: Defining img src with an absolute path - codesd.com

 2 years ago
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

advertisements

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

I have a program that needs to be provided with an absolute path to a particular file - call it xfile located at /home/user/.hidden/sub/sub2/xfile Is there a way to make some sort of replacement function whereby I would type xfile, press TAB and have

Python will not quit when called with an absolute path of cron or subshell

I have some python scripts that run via cron, and they no longer exit correctly when the script is called with an absolute path. They will hang until the process is terminated. I believe it happened after I moved /var and /home to a different partiti

Switching background images with the absolute path of javascript forces

I have a div that begins as follows: <div id="info_picture" style="background-image: url('assets/img/channels/banners/3')"></div> The reason there's no file extension for the image is that it can be uploaded by the user, an

How do you modify img src with javascript depending on browser width?

I would like to change the source of the image element with the id of "front". I have a basic script at the top, but it doesn't work. I was just attempting to come up with something but I'm very bad at JavaScript. <html> <head> <l

Define img src from an input box with jQuery

I'm trying to set the img src based on the value of an input box with jQuery: <img class="preview" id="img" src=""> <input id="form" placeholder="skin URL"> This is the javascript code: $("

Modification of MVC Razor Img src with javascript

This is a MVC application. I have a IEnumberable(Of T) viewmodel that is passed in to the partial view. There will be a next and prev. image button on the lower part of the page. The Idea is simple. When the user clicks the Next Button it shows the n

Change IMG SRC with Javascript

I'm new at javascript and while there are many more complex solutions, I don't understand them and hope I don't have to at this point. I have a main picture... <img src="main-picture.jpg" name="Mainpic" id="image"> ...a

Displaying the image with the absolute path in JSP

I'm using Java, JSP and Jetty to develop a website. I'm having some problem with images paths passed in src of <img> tags. In my database, I have the Linux absolute path of the users' images. I get this value and put into the "src" attribu

Angular 2 img src in a relative path

The johnpapa Angular 2 style guide suggests a folder-by-feature approach. I get the idea, you can make self contained little angular components that can be reused. So, I made a component I wanted to reuse in another project and put it in it's own fol

Changing img src with jQuery without loading the image several times?

I wrote a script using jQuery that changes the src attribute of an img tag in HTML when the window is resized and it works correctly. However, using Chrome's developer tools I noticed that each time that window is resized, the actual image is loaded!

change img src with fadein in jquery

I have this code that fades an image $("#mix").click(function() { $("#mix").addClass("load"); $("#brick-image").stop(true).fadeTo("slow", 0); $("#brick-image").load(function() { $("#mix"

Apache / PHP unable to run convert even when called with an absolute path

I have run into a truly strange issue for which i have no explanation whatsoever. After setting up OS X Yosemite and my local dev environment using XAMPP, i installed ImageMagick through MacPorts. All is well, it runs perfectly fine on the commandlin

Asp includes with an absolute path

is there anyway to do a #include with a file listed as an absolute path? i am trying to include files from other websites (outsite the root of the sight that wants to include it) any other suggestions?You can only include files from your server, thes

How to target img src with jQuery

I have an hidden div with some menu items and a img src which is empty. A user can upload an image which will fill the img src and then I want to show the menu. I've tried this, but I think this does not work because it does not check the img src. $(

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK