Не получается вывести код
Здравствуйте. У меня не получается с помощью document.write вывести html код с елементами джаваскрипта. Какие есть вообще способы такого вывода. Я новичек. Заранее спасибо за помощь)
|
Вот код какой нужно вывести с помощью 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> Или вообще так можно сделать? |
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 --> |
Вы имеете ввиду, что выводить елемент с каким-то id. Но если перед(после) скрипта будет html код, он все равно его выведет, не зависимо будет или нет скрипт.
|
assd18,
Не понял пояснений - поставьте и отпишитесь что не так ... Удалите Внутренний скрипт - Вывода элемента не будет |
Идея вот в чем:
<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> |
Пишу так, но не работает
<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> |
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(); |
Спасибо разобрался) А window.location.pathname возвращает /1.html.
Теперь возник другой вопрос. Как в этом ифе загрузить src файл? |
Цитата:
вы хотите другую картинку подставить? |
<script> if (window.location.pathname == "1.html") { <script type="text/javascript" src="file.js"></script> - как-то так можно? } else { document.write("Hellow"); } </script> |
assd18,
if (window.location.pathname == "1.html") { var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'abc.js'; document.getElementsByTagName('head')[0].appendChild(script); } else { document.write("hellow"); } |
Спасибо, Вы мне очень помогли))))
|
Часовой пояс GMT +3, время: 04:34. |