<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; Запись в контейнер <style>сюда</style>]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=7655&amp;type=atom" />
	<updated>2012-12-13T18:57:22Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=7655</id>
		<entry>
			<title type="html"><![CDATA[Re: Запись в контейнер <style>сюда</style>]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=66953#p66953" />
			<content type="html"><![CDATA[<p>Вот ещё решение (IE5+) (пере)записи таблицы стилей «чистым текстом»:<br /></p><div class="codebox"><pre><code>&lt;HTML&gt;
&lt;HEAD&gt;
&lt;STYLE id=&#039;ss&#039; type=&#039;text/css&#039;&gt;&lt;/STYLE&gt;

&lt;SCRIPT language=&#039;JavaScript&#039; type=&#039;text/javascript&#039;&gt;
var cssText1=&quot;\
  body {color: red;}\
  p {font-weight: bold;}\
&quot;;

var cssText2=&quot;\
  body {background-color: silver;}\
  p {font-style: italic;}\
&quot;;

var styleElement=document.getElementById(&quot;ss&quot;);
var styleSheet=styleElement.styleSheet;
////или вместо предыдущих двух строк:
//var styleSheet=document.styleSheets.item(0);
//// (обратная ссылка на объект HTML-элемента таблицы стилей:
//// styleSheet.owningElement === styleElement)

////Можно создать и на ходу, без предварительного создания элемента &lt;STYLE&gt;:
//var styleSheet=document.createStyleSheet();

window.onload=function () {
  styleSheet.cssText=cssText1;
  window.setTimeout(&#039;styleSheet.cssText=cssText2;&#039;, 2000);
};
&lt;/SCRIPT&gt;
&lt;/HEAD&gt;

&lt;BODY&gt;
&lt;P&gt;Hello, world!&lt;/P&gt;
&lt;/BODY&gt;&lt;/HTML&gt;</code></pre></div>]]></content>
			<author>
				<name><![CDATA[wisgest]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=3850</uri>
			</author>
			<updated>2012-12-13T18:57:22Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=66953#p66953</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Запись в контейнер <style>сюда</style>]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=64727#p64727" />
			<content type="html"><![CDATA[<p>Спасибо, посмотрю.</p>]]></content>
			<author>
				<name><![CDATA[Любитель]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27037</uri>
			</author>
			<updated>2012-10-13T04:45:11Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=64727#p64727</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Запись в контейнер <style>сюда</style>]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=64529#p64529" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Любитель пишет:</cite><blockquote><p>В этом конкретном случае требуется кроссбраузерность, поэтому переписывать внешний файл стилей не подходит.</p></blockquote></div><p>Под «неподходящим» имеется ввиду что-то вроде<br /></p><div class="codebox"><pre><code>&lt;HTML&gt;
&lt;HEAD&gt;
&lt;LINK id=&#039;ss&#039; rel=&#039;stylesheet&#039; type=&#039;text/css&#039; href=&#039;javascript:&quot;&quot;;&#039;&gt;

&lt;SCRIPT language=&#039;JavaScript&#039; type=&#039;text/javascript&#039;&gt;
var cssText1=&quot;\
  body {color: red;}\
  p {font-weight: bold;}\
&quot;;

var cssText2=&quot;\
  body {background-color: silver;}\
  p {font-style: italic;}\
&quot;;

var styleElement=document.getElementById(&quot;ss&quot;);

window.onload=function () {
  styleElement.href=&quot;javascript:cssText1;&quot;;
  window.setTimeout(&#039;styleElement.href=&quot;javascript:cssText2;&quot;;&#039;, 2000);
};
&lt;/SCRIPT&gt;
&lt;/HEAD&gt;

&lt;BODY&gt;
&lt;P&gt;Hello, world!&lt;/P&gt;
&lt;/BODY&gt;&lt;/HTML&gt;</code></pre></div><p>?<br />Хотя я думаю, это решение можно доработать до кроссбраузерного.</p>]]></content>
			<author>
				<name><![CDATA[wisgest]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=3850</uri>
			</author>
			<updated>2012-10-03T17:32:35Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=64529#p64529</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Запись в контейнер <style>сюда</style>]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=64440#p64440" />
			<content type="html"><![CDATA[<p>Не могу перезаписать данные в <strong>&lt;style&gt;&lt;/style&gt;</strong>, во всех браузерах работает, в ИЕ нет. ИЕ читать читает, а изменять отказывается.<br />Пробовал<br /></p><div class="codebox"><pre><code>innerHTML
innerText</code></pre></div><p>и экзотику, эти методы чистый текст пишут, а внутрь <strong>&lt;style&gt;&lt;/style&gt;</strong>, нет<br /></p><div class="codebox"><pre><code>replaceChild()
createTextNode()
insertAdjacentHTML()</code></pre></div><p>Подключать класс или писать стили в каждый элемент, можно, но накладно, слишком много элементов, а так нужно изменить одно единственное место.<br />В этом конкретном случае требуется кроссбраузерность, поэтому переписывать внешний файл стилей не подходит.</p><p>Кто с таким сталкивался? как победили?</p>]]></content>
			<author>
				<name><![CDATA[Любитель]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=27037</uri>
			</author>
			<updated>2012-10-02T03:04:59Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=64440#p64440</id>
		</entry>
</feed>
