Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   Не получается вывести код (https://javascript.ru/forum/dom-window/31284-ne-poluchaetsya-vyvesti-kod.html)

assd18 01.09.2012 13:20

Не получается вывести код
 
Здравствуйте. У меня не получается с помощью document.write вывести html код с елементами джаваскрипта. Какие есть вообще способы такого вывода. Я новичек. Заранее спасибо за помощь)

assd18 01.09.2012 14:07

Вот код какой нужно вывести с помощью javascript
<a href="http://www.i.ua/" target="_blank" onclick="this.href='http://i.ua/r.php?145588';" title="Rated by I.UA">
				<script type="text/javascript" language="javascript"><!--
				iS='<img src="http://r.i.ua/s?u145588&p254&n'+Math.random();
				iD=document;if(!iD.cookie)iD.cookie="b=b; path=/";if(iD.cookie)iS+='&c1';
				iS+='&d'+(screen.colorDepth?screen.colorDepth:screen.pixelDepth)
				+"&w"+screen.width+'&h'+screen.height;
				iT=iD.referrer.slice(7);iH=window.location.href.slice(7);
				((iI=iT.indexOf('/'))!=-1)?(iT=iT.substring(0,iI)):(iI=iT.length);
				if(iT!=iH.substring(0,iI))iS+='&f'+escape(iD.referrer.slice(7));
				iS+='&r'+escape(iH);
				iD.write(iS+'" border="0" width="88" height="31" />');
				//--></script></a>

Или вообще так можно сделать?

Deff 01.09.2012 14:29

assd18,
Пробуйте так:
<a id="Rated_by_I.UA" href="http://www.i.ua/" target="_blank" onclick="this.href='http://i.ua/r.php?145588';" title="Rated by I.UA">
				<script type="text/javascript" language="javascript"><!--
				iS='<img src="http://r.i.ua/s?u145588&p254&n'+Math.random();
				iD=document;if(!iD.cookie)iD.cookie="b=b; path=/";if(iD.cookie)iS+='&c1';
				iS+='&d'+(screen.colorDepth?screen.colorDepth:screen.pixelDepth)
				+"&w"+screen.width+'&h'+screen.height;
				iT=iD.referrer.slice(7);iH=window.location.href.slice(7);
				((iI=iT.indexOf('/'))!=-1)?(iT=iT.substring(0,iI)):(iI=iT.length);
				if(iT!=iH.substring(0,iI))iS+='&f'+escape(iD.referrer.slice(7));
				iS+='&r'+escape(iH);iD=document.getElementById('Rated_by_I.UA');
				iD.innerHTML=iS+'" border="0" width="88" height="31" />';
				//--></script></a>
<!-- pun_debug -->

assd18 01.09.2012 14:46

Вы имеете ввиду, что выводить елемент с каким-то id. Но если перед(после) скрипта будет html код, он все равно его выведет, не зависимо будет или нет скрипт.

Deff 01.09.2012 15:26

assd18,
Не понял пояснений - поставьте и отпишитесь что не так
...
Удалите Внутренний скрипт - Вывода элемента не будет

assd18 01.09.2012 20:03

Идея вот в чем:
<script type="text/javascript">
   if(location.pathname == '/1.html'){
	document.write("а здесь выводится скрипт, который выше."); 	 
	}
	else{
	document.write("Привет");  		
</script>

lord2kim 01.09.2012 20:16

Цитата:

Сообщение от assd18 (Сообщение 202367)
Идея вот в чем:
<script type="text/javascript">
   if(location.pathname == '/1.html'){
	document.write("а здесь выводится скрипт, который выше."); 	 
	}
	else{
	document.write("Привет");  		
</script>

<script>
if (location.pathname == "1.html") {
                iS='<img src="http://r.i.ua/s?u145588&p254&n'+Math.random();
                iD=document;
                if (!iD.cookie) iD.cookie="b=b; path=/";
                if(iD.cookie) iS+='&c1';
                iS+='&d'+(screen.colorDepth?screen.colorDepth:screen.pixelDepth)
                +"&w"+screen.width+'&h'+screen.height;
                iT=iD.referrer.slice(7);
                iH=window.location.href.slice(7);
                ((iI=iT.indexOf('/'))!=-1)?(iT=iT.substring(0,iI)):(iI=iT.length);
                if(iT!=iH.substring(0,iI))iS+='&f'+escape(iD.referrer.slice(7));
                iS+='&r'+escape(iH);
                iD.write(iS+'" border="0" width="88" height="31" />');
}
else {
    document.write("Hellow");
}
</script>

assd18 01.09.2012 20:54

Пишу так, но не работает
<script>
if (location.pathname == "1.html") {
            <a href="http://www.i.ua/" target="_blank" onclick="this.href='http://i.ua/r.php?145588';" title="Rated by I.UA">
            <script type="text/javascript" language="javascript"><!--
            iS='<img src="http://r.i.ua/s?u145588&p254&n'+Math.random();
            iD=document;if(!iD.cookie)iD.cookie="b=b; path=/";if(iD.cookie)iS+='&c1';
            iS+='&d'+(screen.colorDepth?screen.colorDepth:screen.pixelDepth)
            +"&w"+screen.width+'&h'+screen.height;
            iT=iD.referrer.slice(7);iH=window.location.href.slice(7);
            ((iI=iT.indexOf('/'))!=-1)?(iT=iT.substring(0,iI)):(iI=iT.length);
            if(iT!=iH.substring(0,iI))iS+='&f'+escape(iD.referrer.slice(7));
            iS+='&r'+escape(iH);
            iD.write(iS+'" border="0" width="88" height="31" />');
            //--><!--</script></a>
}
else {
    document.write("Hellow");
}
</script>

lord2kim 01.09.2012 21:05

assd18, а как вы под тег script занесли еще один такой же и ссылку...
в таком случае будет выводится в виде ссылки в любом случае, что выполнился ваш скрипт, что нет
<a href="http://www.i.ua/" target="_blank" onclick="this.href='http://i.ua/r.php?145588';" title="Rated by I.UA">
<script>
if (window.location.pathname == "1.html") {
                iS='<img src="http://r.i.ua/s?u145588&p254&n'+Math.random();
                iD=document;
                if (!iD.cookie) iD.cookie="b=b; path=/";
                if(iD.cookie) iS+='&c1';
                iS+='&d'+(screen.colorDepth?screen.colorDepth:screen.pixelDepth)
                +"&w"+screen.width+'&h'+screen.height;
                iT=iD.referrer.slice(7);
                iH=window.location.href.slice(7);
                ((iI=iT.indexOf('/'))!=-1)?(iT=iT.substring(0,iI)):(iI=iT.length);
                if(iT!=iH.substring(0,iI))iS+='&f'+escape(iD.referrer.slice(7));
                iS+='&r'+escape(iH);
                iD.write(iS+'" border="0" width="88" height="31" />');
}
else {
    document.write("Hellow");
}
</script></a>

в таком случае будет выводится только ваш скрипт в виде ссылки, текст "Hellow" будет выводится как простой текст
<script>
if (window.location.pathname == "1.html") {
                iS='<a href="http://www.i.ua/" target="_blank" onclick="this.href='http://i.ua/r.php?145588';" title="Rated by I.UA">';
                iS+='<img src="http://r.i.ua/s?u145588&p254&n'+Math.random();
                iD=document;
                if (!iD.cookie) iD.cookie="b=b; path=/";
                if(iD.cookie) iS+='&c1';
                iS+='&d'+(screen.colorDepth?screen.colorDepth:screen.pixelDepth)
                +"&w"+screen.width+'&h'+screen.height;
                iT=iD.referrer.slice(7);
                iH=window.location.href.slice(7);
                ((iI=iT.indexOf('/'))!=-1)?(iT=iT.substring(0,iI)):(iI=iT.length);
                if(iT!=iH.substring(0,iI))iS+='&f'+escape(iD.referrer.slice(7));
                iS+='&r'+escape(iH);
                iD.write(iS+'" border="0" width="88" height="31" /></a>');
}
else {
    document.write("Hellow");
}
</script>

P.S. возможно window.location.pathname возвращает не 1.html, а /1.html...проверьте с помощью alert();

assd18 04.09.2012 17:12

Спасибо разобрался) А window.location.pathname возвращает /1.html.
Теперь возник другой вопрос. Как в этом ифе загрузить src файл?


Часовой пояс GMT +3, время: 04:47.