0

I have a javascript widget which fetches articles from Wikipedia through MediaWiki API (http://en.wikipedia.org/w/index.php?title=Main_Page&action=render). It's an app for Samsung Smart TVs. Now the text part works fine, but it won't display any images because the img src is structured like this:

"//en.wikipedia.org/wiki/File:example.jpg"

and I've come to realize by using a PC emulator that the Samsung firmware converts it to this type of full url:

"file://localhost/en.wikipedia.org/wiki/File:example.jpg"

Is it possible to add "http:" to the src so that the app points to the correct links hence displaying both thumbnails and full-size images?

Here's the relevant part of the js code:

UIContents.showImage = function(srcURLFromWikiPage, showHigherResolution) {
//    alert("UIContents.fillDescription()");


    var cutURL = srcURLFromWikiPage;

    //document.getElementById('UIContentsImgFrameiFrame').href = srcURL;
    //window.frames.UIContentsImgFrameiFrame.location.href = srcURL + "#file";

    //prepare link for full-size picture:
    //cutURL = cutURL.replace('thumb/','');
    //cutURL = cutURL.substring(0, cutURL.lastIndexOf('/'));

    //show preview thumb version
    //if (cutURL.match(/\.svg$/)) cutURL = srcURLFromWikiPage;
    alert('img src: ' + cutURL);
    //show preview thumb version
    var elemImg = document.getElementById('UIContentsImgFrameImage');

    document.getElementById('UIContentsImgFrame').style.display = 'block';
    //set image source
    if (showHigherResolution == true) elemImg.onload = 'UIContents.resizeImage()';
    elemImg.alt = 'loading...';
    elemImg.src = cutURL;

    elemImg.style.visibility = 'hidden';
    elemImg.style.visibility = 'visible';

    imageViewIsOpened = true;

    document.getElementById('UISearchField').style.visibility = 'hidden';
    document.getElementById('UISearchTextInput').style.visibility = 'hidden';

Any suggestions? Thanks in advance.

Didier Ghys
  • 30,396
  • 9
  • 75
  • 81
GeorgeSh
  • 3
  • 1

1 Answers1

0
var cutURL = srcURLFromWikiPage.replace("file://localhost/","http://");
Phil
  • 1,288
  • 1
  • 10
  • 19
  • Thanks, it works! But how can I fix the thumbnails too? I still get blank thumbnails, it only displays the full-size images correctly after I click on the thumbnails. – GeorgeSh Jun 05 '12 at 10:21