HOME FORUMS MEMBERS RECENT POSTS LOG IN  
× Авторизация
Имя пользователя:
Пароль:
Нет аккаунта? Регистрация
Баннер 1   Баннер 2
НОВЫЕ ТОРГОВАЯ НОВОСТИ ЧАТ
loading...
Скрыть
Вернуться   ANTICHAT > ПРОГРАММИРОВАНИЕ > PHP
   
Ответ
 
Опции темы Поиск в этой теме Опции просмотра

  #1  
Старый 15.02.2009, 19:39
OnArs
Участник форума
Регистрация: 01.08.2008
Сообщений: 239
С нами: 9356016

Репутация: 31
По умолчанию

Здравствуйте, подскажите пожалуйста, как сделать функцию Вывода на печать текущей странице?


Заранее благодарен!
 
Ответить с цитированием

  #2  
Старый 16.02.2009, 02:49
Malunga
Новичок
Регистрация: 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 == || 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, алерт не выполнится......
 
Ответить с цитированием

  #3  
Старый 16.02.2009, 03:29
AkyHa_MaTaTa
Постоянный
Регистрация: 19.03.2007
Сообщений: 684
С нами: 10077446

Репутация: 1020


По умолчанию

Ну а с чего ты взял что XMLHttpRequest будет вести себя как браузер? Естественно что js код находяшейся на другой странице магическим образом не выполниться, равно как и не произойдет загрузка всех картинок, css, flash, представь сколько заняло бы все это времени, жуть, парси ответ например match(/<script>(.*)</script>/) ну делай eval отпарсиных данных.
 
Ответить с цитированием

  #4  
Старый 16.02.2009, 09:33
spamoney
Участник форума
Регистрация: 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 сбрасывалось на первое значение (Выберите Фон)
 
Ответить с цитированием

  #5  
Старый 16.02.2009, 12:57
it's mу
Banned
Регистрация: 12.02.2009
Сообщений: 73
С нами: 9075206

Репутация: 171
По умолчанию

У меня такой вопрос, можно ли через <body onload=javascript:... сделать так, что бы загружалась страница в ифреме?
 
Ответить с цитированием

  #6  
Старый 16.02.2009, 13:06
Корвин
Участник форума
Регистрация: 26.02.2007
Сообщений: 259
С нами: 10107625

Репутация: 67
По умолчанию

spamoney, помоему такое не получится сделать
 
Ответить с цитированием

  #7  
Старый 17.02.2009, 20:44
Doom123
Постоянный
Регистрация: 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 никада не работал и не пойму как скрипт к форме привязать =\\
 
Ответить с цитированием

  #8  
Старый 18.02.2009, 13:36
DMajere
Познающий
Регистрация: 25.12.2008
Сообщений: 34
С нами: 9145978

Репутация: 6
По умолчанию

подскажите, есть ли в javascript функции аналогичные
strip_tags(), addslashes и trim
 
Ответить с цитированием

  #9  
Старый 18.02.2009, 13:49
Корвин
Участник форума
Регистрация: 26.02.2007
Сообщений: 259
С нами: 10107625

Репутация: 67
По умолчанию

Цитата:
Сообщение от DMajere  
подскажите, есть ли в javascript функции аналогичные
strip_tags(), addslashes и trim
PHP код:

function strip_tagsstr )
{    
    return 
str.replace(/<\/?[^>]+>/gi'');
}

function 
addslashesstr 
{
    return (
str+'').replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0");
}


function trim(string)
{
return string.replace(/(^\s+)|(\s+$)/g, "");

провда не проверял, пашет или нет, вот проверишь напиши=)
 
Ответить с цитированием

  #10  
Старый 18.02.2009, 13:52
DMajere
Познающий
Регистрация: 25.12.2008
Сообщений: 34
С нами: 9145978

Репутация: 6
По умолчанию

спасибо за код. я так понял, что встроенных подобных функций нет?


хм. отчего-то не работает ваш код, Корвин

даже могу сказать почему. в первой функции использован обр слеш как ограничитель шаблона

(/</?[^>]+>/gi, '')
шаблон будет закрываться раньше. ну да это ничего. это мы сами допрем)))

еще раз спасибо за ответ

Последний раз редактировалось DMajere; 18.02.2009 в 16:08..
 
Ответить с цитированием
Ответ



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
[Delphi]/[Pascal] Задай вопрос, получи ответ Isis С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby 6762 17.06.2010 21:23



Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
 


Быстрый переход




ANTICHAT ™ © 2001- Antichat Kft.

×

Создать сделку

Продавец: ник или ID

Название сделки:

Сумма USDT:

Срок сделки, дней:

Кто платит комиссию:

Условия сделки:

После создания сделки средства будут зарезервированы в холде до завершения сделки.

×

Мои сделки

Загрузка...
×

Сделка


Загрузка чата...
×

ESCROW ADMIN PANEL

Загрузка...
Загрузка...