문제

I see that Dart has a BodyElement class, and that it has an innerHTML property.

I also see that you can access the current document's body via window.document.body, however, there are no getter/setter methods for this body property.

So I'm trying to link the two together: how I dyamically set the current document's body's inner HTML? I'm looking for something like:

String html = "<p><h1>I'm dynamic</h1>";
window.document.body = bodyElementFactory.newBodyElement(html);
도움이 되었습니까?

해결책 2

Some options:

querySelector('body').appendHtml("<p><h1>I'm dynamic</h1>");

or

querySelector('body').innerHtml = "<p><h1>I'm dynamic</h1>";

다른 팁

this should work for dart 1.14+

String html = "<p><h1>I'm dynamic</h1>";
querySelector('body').setInnerHtml(html);

document.body returns BodyElement. You could do the following if you wanted:

document.body.innerHtml = "<h1>I'm dynamic</h1>";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top