CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Jul 2006
    Posts
    19

    Javascript problem with IE7

    Hi Folks,

    I got a problem with some of my scripts with the new version of the
    internet explorer (7.0).

    It seems like this kind of assign:

    document.anyimage.src= "c:\car.jpg"

    does not work anymore.
    I used it on an "OnChange" event for File2Upload elements, so an user was able to see his selection immediately, worked fine in IE6.
    It still works in IE7, but only with a relatative path like "../images/car.jpg".

    Can anyone give me a hint on this? Sadly, File2Upload elements return an absolute path.. what can I do on this?
    Last edited by AndyTheAce; December 14th, 2006 at 09:14 AM.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Javascript problem with IE7

    I believe that in IE7 it was finally realized by Microsoft that giving the full path and not a URL path to a file or any such source was a security hole.

    You can test it by creating an image and giving it just a direct path using the C:\Path\file as the source.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jul 2006
    Posts
    19

    Re: Javascript problem with IE7

    I already did as I described, it does not work even with a hardcoded absolute path.

    So.. what could you do now if you want to display a selected image
    immediatly after selecting it (i.e. with file2upload) ?

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Javascript problem with IE7

    EDIT: I just tried the following on IE 7 on my work machine it shows fine.

    Code:
    <img src="G:\Apache2\htdocs\images\work.jpg">
    Last edited by PeejAvery; December 14th, 2006 at 10:27 AM.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jul 2006
    Posts
    19

    Re: Javascript problem with IE7

    maybe be ..
    Didn't try with html, I need it badly working with javascript.

    tried it with document.anyimage.src= "c:\car.jpg" ?

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: Javascript problem with IE7

    Just use a div and rewrite the content.

    Code:
    <div id="imagediv"></div>
    
    <script language="JavaScript">
      document.getElementById('imagediv').innerHTML = "<img src='c:\car.jpg'>";
    </script>
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Jul 2006
    Posts
    19

    Re: Javascript problem with IE7

    First of all, thanks for your help PeejAvery,

    I did it like you suggest, but I'm experiencing some problems.

    this is the line of code for changing the picture:

    document.getElementById('ctl00_ContentPlaceHolder1_lblimage').innerHTML = "<img id='userimg' width='200' height='240' src='" + document.getElementById('ctl00_ContentPlaceHolder1_FileUpload1').value + "'>";

    Its just the same way you suggested, just with some long id's.
    On the first view it seems to work, but IE7 does not show the image after all!

    I made two screenshots for demonstration, this is the above line of code outputed with alert:

    http://meet2poker.tempw7.internet1.de/temp/output.jpg

    As you can see, it executes the code correctly, but the image is not displayed.

    Second screenshot shows the information about the picture:

    http://meet2poker.tempw7.internet1.de/temp/file.jpg

    It looks like.. he still does not know where the file is located, it just got the filename without the path ?!? I don't know why.. but the src line is correct as you can see in screenshot one.

    Doohh I'm confused.

  8. #8
    Join Date
    May 2002
    Posts
    10,943

    Re: Javascript problem with IE7

    What does the following code do for you?

    Code:
    <html>
    <body>
    
    <script language="JavaScript">
    function showimage(){
      var img = "<img id='userimg' width='200' height='240' src='" + document.getElementById('ctl00_ContentPlaceHolder1_FileUpload1').value + "'>";
      document.getElementById('ctl00_ContentPlaceHolder1_lblimage').innerHTML = img;
    }
    </script>
    
    <div id="ctl00_ContentPlaceHolder1_lblimage"></div>
    <input type="file" id="ctl00_ContentPlaceHolder1_FileUpload1" onchange="showimage()">
    
    </body>
    </html>
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  9. #9
    Join Date
    Jul 2006
    Posts
    19

    Re: Javascript problem with IE7

    that code works with a normal html file (IE7 asks me for allowing active content bla bla if I open this in html)

    If I put the code to the output of my aspx its the same as I describe in my previous post, no asking for active content, executing the code but NOT showing the picture.

  10. #10
    Join Date
    May 2002
    Posts
    10,943

    Re: Javascript problem with IE7

    I would suggest going to Microsoft about it. Contact them. Since IE 7 is rather new, all the knowledge base still is not compiled.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  11. #11
    Join Date
    Jul 2006
    Posts
    19

    IE7 and "the path" part II

    Hola,

    I posted this problems a few weeks ago, discussed it with PeejAvery coming to no solution.
    Maybe anyone knows something new about it or a workaround:

    Simple problem, since IE7 it's not possible to set an absolute file path for example an image.
    An assignment like <img src="C:\mypic.jpg"> is recognized but not displayed, except you execute that code on your localhost.

    It's possibly some kind of new security option, but it's pretty annoying if you want some kind of preview of an image (file2upload).

    If there is any idea out there, I'm happy to hear it.

    Best Regards,
    Andy

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured