WHAT'S NEW?
Loading...

Mendapatkan Nama File dari URL


//in HTML
<img id="image" src="http://1.bp.blogspot.com/-gopq8JTSuxg/UEloesUz1aI/AAAAAAAAEd4/rAwnC-C2AWE/s72/Cacing+Kepanasan.jpg" alt="">
<h2 id="title-container"></h2>

//Javascript code

function getTitle(str) {
    var a = str.lastIndexOf('/') + 1,
        b = str.lastIndexOf('.');
    str = decodeURIComponent(str.substring(a, b));
    str = str.replace(/[\+\-\_]/g, " ");
    return str;
}

var title = document.getElementById('image').src;
document.getElementById('title-container').innerHTML = getTitle(title);

0 komentar:

Post a Comment