/    Sign up×
Community /Pin to ProfileBookmark

document.designMode not working in Firefox, when CSS file is specified

I have a been working on a rich-text editor for a web app we are writing and have come across an issue with designMode. Basically, if I document.write a <link> tag in, for a stylesheet, Firefox renders the stylesheet but will not switch to design mode. This approach works in IE6/7 (basic snippet below):

[CODE]
// SNIPPED…
this.SetFrameHtml = function(html)
{
var editDoc = this.GetDocument();
if (!Compatibility.IsNull(editDoc))
{
this.frameObject.src = ‘about:blank’;
editDoc.open();
editDoc.write(‘<html><head>’);
if (!Compatibility.IsNull(this.cssFile) && this.cssFile != ”)
editDoc.write(‘<link rel=”stylesheet” type=”text/css” media=”all” href=”‘ + this.cssFile + ‘” />’);
editDoc.write(‘</head><body>’);
editDoc.write(html);
editDoc.write(‘</body></html>’);
editDoc.close();
}

if (!Compatibility.IsNull(this.inputObject))
this.inputObject.value = html;
}
// …SNIPPED…
this.cssFile = cssFile;
this.SetFrameHtml(this.initHtml);
this.GetDocument().designMode = ‘on’;
// …SNIPPED
[/CODE]

If this.cssFile is null or empty, it will work in IE and FF, but if cssFile is populated, the mode never switches.

Does anyone have any ideas why?

J.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Spud999Jun 28.2008 — Did anyone ever come up with a solution to this? I've just encountered the same problem.
Copy linkTweet thisAlerts:
@jimbobmcgeeauthorJun 30.2008 — The only way I ever got around it was to load the CSS file server-side and inject it into a <style /> block. In my case, I changed the cssFile variable to cssString and passed raw CSS to the method.

It wasn't pretty, but it was the only way I could find that worked during the timeframe that I had. It may also be possible to load the CSS file client-side, with an AJAX-style call, but I didn't at the time.

J.
×

Success!

Help @jimbobmcgee spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...