Prevent selection being greyed out in iframe in Firefox without using contenteditable

前端 未结 3 1681
天涯浪人
天涯浪人 2021-02-19 10:45

In Firefox 3 and later (and probably older versions), selecting content within an iframe always seems to use the grey selection background colour used for a document that doesn\

3条回答
  •  我在风中等你
    2021-02-19 11:15

    I just tried to reproduce the problem with a "real" page as iframe content and then it works like you want: blue colored selection! (FF 5.0)

    see: http://jsfiddle.net/97Vjz/8/

    It seems only generated content has this problem, so you could make a page (php/asp(x)) that generates the content for you to circumvent the problem.

    Another solution to use javascript generated content is to load it with src="javascript:''" (actually this is Tim's own solution from the comments below.)

    A simple example script: http://jsfiddle.net/97Vjz/9/

     iframe.src='javascript:\'' + content + '\'';
    

提交回复
热议问题