Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 829 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Jscript image tag creation gives an error

#1
function pushImage () {
var img = new Image();
img.src = '/waroot/chart/chart.png';
document.getElementById("test1").innerHTML = "<img src='/waroot/chart/chart.png'>";
document.getElementById("test2").innerHTML = img;
}

Test 1 works and shows the image, but test 2 doesn't. I am not sure how to solve it but i will need the way test 2 works further along my project since i'm going to have to circle through a large amount of images.

The images are created by `JFreeCharts`, saved to `png` and then have to be posted to a site. As a side question: is it possible to push the freecharts objects straight to the `jscript` instead of having to save them prior (i could throw them into the dictionary and then look them up later but i'm not sure if this works)
Reply

#2
Use `.appendChild(img)` instead of `.innerHTML`:

function pushImage () {
var img = new Image();
img.src = '/waroot/chart/chart.png';
document.getElementById("test1").innerHTML = "<img src='/waroot/chart/chart.png'>";
document.getElementById("test2").appendChild(img);
}

<a href="http://jsfiddle.net/d9Pvp/">Demo</a>

This is because `img` is an image object, not an html string, so you have to append it to the DOM.

P.S., don't forget that the `alt` attribute is required in the `img` tag!
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through