SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    preview images in Mozilla

    This code works in IE (preview uploaded images)
    How to make it working in Mozilla?

    Code:
     
    function DoPreview(field, img) {
     
     var img = document.getElementById(img);
     var field = document.getElementById(field);
      
     //var new_img = new Image();
     img.width = 100;
     img.src = field.value;
    }
      
    <input type="file" name="patient_file" id="patient_file" onFocus="DoPreview('patient_file','patient_img')">

  2. #2
    SitePoint Guru bronze trophy blufive's Avatar
    Join Date
    Mar 2002
    Location
    Manchester, UK
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You've only given us part of the page, any chance we can see it all?

    Anyhow, I've had a poke around in Moz's javascript debugger, and it certainly appears that the text in the input box *IS* ending up in the src attribute of the image tag.

    I *think* the problem (at least on windows) is that the src attribute is ending up containing something like "c:\images\myimage.gif" - which is NOT a valid image URL. The backslashes ("\") are a killer, for a start, and the "c:" is almost certainly getting misinterpreted as a protocol identifier (like "http:")

    IE copes, but only because it's doing double duty as the windows filesystem browser. Opera comes a cropper, too. It appears to be suffering the same fate as mozilla, for what I assume is the same reason.

    The only obvious solution would be to somehow translate the windows file path into a proper "file:///...." url.

    For which you'll need someone who can cope with heavy JS string manipulation without their head exploding, which rules me out, especially at this time of night...

  3. #3
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have Moz 1.5 on Win2K. It seems that Moz doesn't fire the focus event when the text field is focused - but it does fire the focus event when the button is focused (tab to it). For an INPUT element with type='text' it works as expected.

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The only obvious solution would be to somehow translate the windows file path into a proper "file:///...." url.
    Yes, problem is here
    how to solve it?

  5. #5
    SitePoint Zealot Vogelfrei's Avatar
    Join Date
    Jan 2004
    Location
    west of the divide
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by onesign
    Yes, problem is here
    how to solve it?
    HTML Code:
    src = "file://" + (ctrl.value.indexOf('/')==0 ? '' : '/' ); // file + 3 slashes 
    src += ctrl.value.replace(/\\/g,"/"); // Convert Windows backslashes to foreward slashes
    newimg.src = src;


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •