SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Differents result for browsers...

    I'm having big trouble figuring out hopw to solve this. I'm trying to make an small wysigwyg editor with image insert, and everything is working greate except one thing...

    When using Internet Explorer it works fine and comes out like this:
    Code:
    <img src="myimage.jpg style="float:left">
    But when using safari or Google Chrome the same comes out like this:
    Code:
    <img src="myimage.jpg style=&quot;float:left&quot;">
    It have replaced the "" with &quot;.

    I'm using this to insert the image after upload:
    Code JavaScript:
    var imageURL = returnValue;
    var style = ' style="float:left"';
    var imageURL = imageURL+style;
    //alert(imageURL);
    test.execCommand("insertimage", imageURL);

    How do I solve this???

    Thanks in advance :-)

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Is this script dynamically inserting images? If so its a very odd and inconsistant way to do so. The way this should be done is by using the DOM to create an IMG element and set its attributes like the example below.

    Code JavaScript:
    // Set the element to append the new img element
    // to
    var ele = document.getElementById('element_id');
     
    // Create the element
    var img = document.createElement('img');
     
    // Set the attributes
    img.setAttribute('src', imageURL);
    img.setAttribute('style', 'float: left;');
     
    // Append the new child element "img"
    ele.appendChild(img);
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle


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
  •