
15.02.2009, 19:39
|
|
Участник форума
Регистрация: 01.08.2008
Сообщений: 239
С нами:
9356016
Репутация:
31
|
|
Здравствуйте, подскажите пожалуйста, как сделать функцию Вывода на печать текущей странице?
Заранее благодарен!
|
|
|

16.02.2009, 02:49
|
|
Новичок
Регистрация: 03.09.2008
Сообщений: 13
С нами:
9307922
Репутация:
8
|
|
Всем привет. Столкнулся с такой проблемой как получение тега <script> через ajax.
На странице 1 выполняется запрос к странице 2 путём ajax. 2-я страница содержит JS-код (в тегах <script></script>). Но этот код не выполняется при получении на странице 1. Подскажите как это реализовать?
Простой пример (если вдруг плохо обьяснил):
страница 1
PHP код:
<script type="text/javascript">
httpRequest = new XMLHttpRequest();
function listen(divId){
function result(){
if (httpRequest.readyState == 4 || httpRequest.readyState == 'complete'){
var result = httpRequest.responseText;
document.getElementById(divId).innerHTML = result;
}
}
httpRequest.open('GET', '2.php', true);
httpRequest.send(null);
httpRequest.onreadystatechange = result;
}
</script>
<div id="num" onclick="listen('num')">какой то текст!!</div>
2 страница
PHP код:
<script>alert('TEXT')</script>
Но при получении на странице 1, алерт не выполнится......
|
|
|

16.02.2009, 03:29
|
|
Постоянный
Регистрация: 19.03.2007
Сообщений: 684
С нами:
10077446
Репутация:
1020
|
|
Ну а с чего ты взял что XMLHttpRequest будет вести себя как браузер? Естественно что js код находяшейся на другой странице магическим образом не выполниться, равно как и не произойдет загрузка всех картинок, css, flash, представь сколько заняло бы все это времени, жуть, парси ответ например match(/<script>(.*)</script>/) ну делай eval отпарсиных данных.
|
|
|

16.02.2009, 09:33
|
|
Участник форума
Регистрация: 26.12.2006
Сообщений: 107
С нами:
10196899
Репутация:
27
|
|
Здравствуйте, такой вопрос:
Есть поле select, в котором несколько пунктов, как сделать так, что бы после выбора кого-либо значения, выбранное значение сбрасывалось на первое в этом списке...
т.е допустим есть:
Код:
<div><select style="font-size: 10px;" name="background" onchange=\"InsertCode('".$id."','background', this.options[this.selectedIndex].value)\">
<option style="background-color: white; color:black;" value="white">Выберите Фон</option>
<option style="background-color: #F58A8A;" value="#F58A8A">Фон F58A8A</option>
<option style="background-color: #C00000;" value="#C00000">Фон C00000</option>
</select></div>
Нужно что б после выбора, любого фона (допустим Фон C00000), поле select сбрасывалось на первое значение (Выберите Фон)
|
|
|

16.02.2009, 12:57
|
|
Banned
Регистрация: 12.02.2009
Сообщений: 73
С нами:
9075206
Репутация:
171
|
|
У меня такой вопрос, можно ли через <body onload=javascript:... сделать так, что бы загружалась страница в ифреме?
|
|
|

16.02.2009, 13:06
|
|
Участник форума
Регистрация: 26.02.2007
Сообщений: 259
С нами:
10107625
Репутация:
67
|
|
spamoney, помоему такое не получится сделать
|
|
|

17.02.2009, 20:44
|
|
Постоянный
Регистрация: 11.11.2006
Сообщений: 834
С нами:
10262314
Репутация:
668
|
|
Код HTML:
<script type="text/javascript">
//Javasript BBC text editor designed by Rakuli - www.openthource.com (You can get rid of this if you want ;)
// Javascript can have abstraction too, so let's abstract just about EVERYTHING
// Let's define the class In this one I have hard-coded a lot of things which kinda sux but we'll live
// it still makes thing easier to change later on...
// The code here will be longer than your current code but nothing will be embedded in your html
function createTextEditor(txtName)
// this takes the name of the textarea which needs to also be the name of the variable (just for ease of user and self referencing)
// We will create the variable later using var myTextEditor = new createTextEditor('myTextEditor');
{
this.id = txtName; // Name our object
this.textarea = document.getElementById(txtName); // Store a reference to textarea
this.textarea.onselect = function () {this.storeCursor(this)};
this.textarea.onchange = function () {this.storeCursor(this)};
this.textarea.onkeyup = function () {this.storeCursor(this)};
this.textarea.onclick = function () {this.storeCursor(this)};
this.textarea.storeCursor = function () {
// Make it easier to track the cursor in IE
if (typeof(this.createTextRange) != "undefined")
this.cursorPos = document.selection.createRange().duplicate();
};
// Okay, now we'll create an object for each of the formatting options you want
// Same as the main, pass the ID of the
// To ease everything we'll give each child a parent propery
this.boldText = new createSimpleText('boldText', 'Bold', 'b', this);
this.italicText = new createSimpleText('italicText', 'Italicise', 'i', this);
this.underLine = new createSimpleText('underLine', 'Underline', 'u', this);
this.mail = new createSimpleText('mail', 'Email', 'mail', this);
this.quote = new createSimpleText('quote', 'Quote', 'quote', this, '[quote=AuthorName]Text[/quote]');
this.url = new createSimpleText('url', 'URL', 'url', this, '[url=URL]Link Name[/url]');
this.fontColor = new createSelectBoxText('fontColor', 'Font Color', 'color', this, '[color=colorName]Text[/color]');
this.fontSize = new createSelectBoxText('fontSize', 'Font Size', 'size', this, '[size=fontSize]Text[/size]');
//the ID of the help box
this.helpBox = document.getElementById('helpBox');
this.showHelp = function (helpTxt)
{
this.helpBox.innerHTML = helpTxt;
};
this.updateText = function (tagOpen, tagClose)
{
// See if we have a selection and whether to replace or add or just slot in
// IE makes this easy because we used the onselect function earlier
if (typeof(this.textarea.cursorPos) != "undefined" && this.textarea.createTextRange)
{
var cursorPos = this.textarea.cursorPos, stored_length = cursorPos.text.length;
cursorPos.text = cursorPos.text.charAt(cursorPos.text.length - 1) == ' ' ? tagOpen + cursorPos.text + tagClose + ' ' : tagOpen + cursorPos.text + tagClose;
// If we are just inserting the tag where the cursor is sitting then we will place the cursor
// between the tags (nifty ;) )
if (stored_length == 0)
{
cursorPos.moveStart("character", -tagClose.length);
cursorPos.moveEnd("character", -tagClose.length);
cursorPos.select();
}
else
this.textarea.focus(cursorPos);
}
// A little bit messier with REAL browsers ...
else if (typeof(this.textarea.selectionStart) != "undefined")
{
// store the text before the selection
var strt = this.textarea.value.substr(0, this.textarea.selectionStart);
// the actual selected text
var selection = this.textarea.value.substr(this.textarea.selectionStart, this.textarea.selectionEnd - this.textarea.selectionStart);
// store the text after the selection
var fin = this.textarea.value.substr(this.textarea.selectionEnd);
// put the cursor at the endo of the selection
var cursorPos = this.textarea.selectionStart;
var scrollPos = this.textarea.scrollTop; // make sure the cursor isn't invisible when we place it in
this.textarea.value = strt + tagOpen + selection + tagClose + fin; // Write the tags
if (this.textarea.setSelectionRange)
{
if (selection.length == 0)
// put the cursor in the middle again if nothing is selected
this.textarea.setSelectionRange(cursorPos + tagOpen.length, cursorPos + tagOpen.length);
else
// else place the cursor after the tag
this.textarea.setSelectionRange(cursorPos, cursorPos + tagOpen.length + selection.length + tagClose.length);
this.textarea.focus();
}
// scroll the required position
this.textarea.scrollTop = scrollPos;
}
// Dunno what happened here, something went wrong so just plug it at the end...
else
{
this.textarea.value += tagOpen + tagClose;
this.textarea.focus(this.textarea.value.length - 1);
}
}
this.insertSingleTag = function (tag) // This will insert a sinlge tag (like smilies or a <br /> or something)
{
// Pretty much same as above, but just one tag going in (this will overwrite selected text -- like pasting sometthing would)
// Thankfully IE makes this easier too
if (typeof(this.textarea.cursorPos) != "undefined" && this.textarea.createTextRange)
{
var cursorPos = this.textarea.cursorPos;
cursorPos.text = cursorPos.text.charAt(cursorPos.text.length - 1) == ' ' ? tag + ' ' : tag;
cursorPos.select();
}
// But messiness comes with real browsers
else if (typeof(this.textarea.selectionStart) != "undefined")
{
var strt = this.textarea.value.substr(0, this.textarea.selectionStart);
var fin = this.textarea.value.substr(this.textarea.selectionEnd);
var scrollPos = this.textarea.scrollTop;
this.textarea.value = strt + tag + fin
if (this.textarea.setSelectionRange)
{
this.textarea.focus();
this.textarea.setSelectionRange(strt.length + tag.length, strt.length + tag.length);
}
this.textarea.scrollTop = scrollPos;
}
// Just put it on the end.
else
{
this.textarea.value += tag;
this.textarea.focus(this.textarea.value.length - 1);
}
}
}
// Basically pass the id of the input, the name of the style, the opening tag, the closing tag, the parent and optionally an additional bit of text
// Use this function for creating simple things like [u][/u] [quote][/quote] where nothing needs to be dynamically added to the BBC tags..
function createSimpleText(inpName, txtName, tag, theParent, addHelpTxt)
{
this.inpName = document.getElementById(inpName); // store an object reference
this.inpName._parent = theParent;
this.inpName.tagOpen = '[' + tag + ']'; // wrap up the tag in the square brackets
this.inpName.tagClose = '[/' + tag + ']';
this.inpName.helpString = '<strong>' + txtName + ' Text : </strong> ' + this.inpName.tagOpen + ' text ' + this.inpName.tagClose + (addHelpTxt ? ' or ' + addHelpTxt : '');
this.inpName.onmouseover = function () { this._parent.showHelp(this.helpString); };
this.inpName.onmouseout = function () { this._parent.showHelp('');};
this.inpName.onclick = function () { this._parent.updateText(this.tagOpen, this.tagClose);};
}
function createSelectBoxText (inpName, txtName, tag, theParent, addHelpTxt)
{
this.inpName = document.getElementById(inpName); // store an object reference
this.inpName._parent = theParent;
this.inpName.tagOpen = '[' + tag + '='; // add the parameter from the value of the selectBox
this.inpName.tagClose = '[/' + tag + ']';
this.inpName.helpString = '<strong>' + txtName + ': </strong> ' + addHelpTxt;
this.inpName.onmouseover = function () { this._parent.showHelp(this.helpString); };
this.inpName.onmouseout = function () { this._parent.showHelp('');};
this.inpName.onchange = function () { this._parent.updateText(this.tagOpen + this.options[this.selectedIndex].value + ']', this.tagClose);};
}
</script>
есть код а как его юзать хз =) с JS никада не работал и не пойму как скрипт к форме привязать =\\
|
|
|

18.02.2009, 13:36
|
|
Познающий
Регистрация: 25.12.2008
Сообщений: 34
С нами:
9145978
Репутация:
6
|
|
подскажите, есть ли в javascript функции аналогичные
strip_tags(), addslashes и trim
|
|
|

18.02.2009, 13:49
|
|
Участник форума
Регистрация: 26.02.2007
Сообщений: 259
С нами:
10107625
Репутация:
67
|
|
Сообщение от DMajere
подскажите, есть ли в javascript функции аналогичные
strip_tags(), addslashes и trim
PHP код:
function strip_tags( str )
{
return str.replace(/<\/?[^>]+>/gi, '');
}
function addslashes( str )
{
return (str+'').replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0");
}
function trim(string)
{
return string.replace(/(^\s+)|(\s+$)/g, "");
}
провда не проверял, пашет или нет, вот проверишь напиши=)
|
|
|

18.02.2009, 13:52
|
|
Познающий
Регистрация: 25.12.2008
Сообщений: 34
С нами:
9145978
Репутация:
6
|
|
спасибо за код. я так понял, что встроенных подобных функций нет?
хм. отчего-то не работает ваш код, Корвин
даже могу сказать почему. в первой функции использован обр слеш как ограничитель шаблона
(/</?[^>]+>/gi, '')
шаблон будет закрываться раньше. ну да это ничего. это мы сами допрем)))
еще раз спасибо за ответ
Последний раз редактировалось DMajere; 18.02.2009 в 16:08..
|
|
|
|
 |
|
|
Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
|
|
|
|