Why doesn't IE7 copy
 blocks to the clipboard correctly?

后端 未结 7 1072
一生所求
一生所求 2021-02-03 19:20

We\'ve noticed that IE7 has an odd behavor with code blocks posted on Stack Overflow. For example, this little code block:

public PageSizer(string href, int inde         


        
7条回答
  •  攒了一身酷
    2021-02-03 20:11

    @Jeff Atwood It's the right idea, but the implementation still needs work. I guess my air code just didn't cut it :)

    I suspect that the fix I mentioned earlier doesn't work because prettify is doing some additional processing on the text after line ~1000 is called.

    Trying to track the content backwards from when it's added to the page, I came across this comment around line 1227:

    
    // Replace 
    s with line-feeds so that copying and pasting works // on IE 6. // Doing this on other browsers breaks lots of stuff since \r\n is // treated as two newlines on Firefox, and doing this also slows // down rendering.

    When I took the isIE6 condition off of the code, it mostly worked in IE7 (there was an extra line break at the top and bottom), and Firefox 3... But I'd assume that it causes issues with older versions of FFX.

    At the very least, it appears that IE7 will require \r\n, instead of just \n. Figuring out exactly what will work with which browsers will take a more extensive test setup than I have handy at the moment.

    Anyway, inserting the \r\n for IE7 appears to be basically what needs to happen. I'll keep poking around prettify to see if I can narrow it down further.

    UPDATE: IE7 appears to strip newline characters (\r or \n) from strings that are assigned to an innerHTML property. It looks like they need to be added back in, around line 1227.

    A correct solution would probably mean inserting a placeholder tag around line 1000, and then replacing it around line 1227.

提交回复
热议问题