Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/topic.php on line 737
Форумы портала PHP.SU :: доступ к содержимому iframe

 PHP.SU

Программирование на PHP, MySQL и другие веб-технологии
PHP.SU Портал     На главную страницу форума Главная     Помощь Помощь     Поиск Поиск     Поиск Яндекс Поиск Яндекс     Вакансии  Пользователи Пользователи


 Страниц (1): [1]   

> Без описания
dimalogin
Отправлено: 01 Июня, 2007 - 00:15:38
Post Id



Новичок


Покинул форум
Сообщений всего: 24
Дата рег-ции: Апр. 2007  
Откуда: Санкт-Петербург


Помог: 0 раз(а)




Здраствуйте, есть страница на которой есть
<iframe src='count_user_local.php' name='count_user_iframe' id='count_user_iframe' width='24' height='12' scrolling='no' frameborder='0'></iframe>

на count_user_local.php есть тег <b id="into_b">slovo</b>

Как посредством Javascript получить содержимое тега <b></b>, находясь на странице с <iframe>?

document.getElementById("count_user_span").document.getElementById("cinto_b").firstChild.data;
не работает.

как это реализовать с поддержкой DOM?
Спасибо.
 
 Top
evgenijj
Отправлено: 01 Июня, 2007 - 09:17:50
Post Id



Участник


Покинул форум
Сообщений всего: 1212
Дата рег-ции: Авг. 2006  
Откуда: Москва


Помог: 10 раз(а)




Цитата:

Iframe как таковой имеет две ипостаси -- HTML-объект (подобно <div> ) и окно (типа window). К первой ипостаси мы обращаемся через document.getElementById(...), а ко второй -- через window.frames[...]. Поэтому бессмысленно пытаться обращаться к стилям у window.frames['myiframe'] или менять location у document.getElementById('myiframe'). Хотя у "ифрейма" как HTML-объекта есть свойства contentDocument (Mozilla практически вся, Opera 7+) и contentWindow (Mozilla 0.9.4+, MSIE 5.5+. Все Оперы включая 7.50 - не поддерживают), обратившись к которому, мы получаем содержащийся в ифрейме документ или окно. У contentDocument есть "обратное" свойство - defaultView (Mozilla, MSIE 5.5+, Opera 7+). Т. е.

iframe.contentDocument.defaultVi ew == iframe.contentWindow

Примечание: очевидно, что

iframe.contentWindow.document == iframe.contentDocument


Другими словами, чтобы твой код работал во всех браузерах, придется долго исполнять шаманские пляски с бубном. Для MS IE должно работать так:

document.getElementById("myIFrame").contentWindow.document.getElementById("myform").elements["text1"].value
 
 Top
dimalogin
Отправлено: 01 Июня, 2007 - 21:59:59
Post Id



Новичок


Покинул форум
Сообщений всего: 24
Дата рег-ции: Апр. 2007  
Откуда: Санкт-Петербург


Помог: 0 раз(а)




Вот нашел Улыбка))))) Динамическое создание iframe и поддержка всех браузеров!!!

Цитата:
var IFrameObj; // our IFrame object
function callToServer() {
if (!document.createElement) {return true};
var IFrameDoc;
var URL = 'server.html';
if (!IFrameObj && document.createElement) {
// create the IFrame and assign a reference to the
// object to our global variable IFrameObj.
// this will only happen the first time
// callToServer() is called
try {
var tempIFrame=document.createElement('iframe');
tempIFrame.setAttribute('id','RSIFrame');
tempIFrame.style.border='0px';
tempIFrame.style.width='0px';
tempIFrame.style.height='0px';
IFrameObj = document.body.appendChild(tempIFrame);

if (document.frames) {
// this is for IE5 Mac, because it will only
// allow access to the document object
// of the IFrame if we access it through
// the document.frames array
IFrameObj = document.frames['RSIFrame'];
}
} catch(exception) {
// This is for IE5 PC, which does not allow dynamic creation
// and manipulation of an iframe object. Instead, we'll fake
// it up by creating our own objects.
iframeHTML='<iframe id="RSIFrame" style="';
iframeHTML+='border:0px;';
iframeHTML+='width:0px;';
iframeHTML+='height:0px;';
iframeHTML+='"></iframe>';
document.body.innerHTML+=iframeHTML;
IFrameObj = new Object();
IFrameObj.document = new Object();
IFrameObj.document.location = new Object();
IFrameObj.document.location.ifra me = document.getElementById('RSIFrame');
IFrameObj.document.location.repl ace = function(location) {
this.iframe.src = location;
}
}
}

if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
// we have to give NS6 a fraction of a second
// to recognize the new IFrame
setTimeout('callToServer()',10);
return false;
}

if (IFrameObj.contentDocument) {
// For NS6
IFrameDoc = IFrameObj.contentDocument;
} else if (IFrameObj.contentWindow) {
// For IE5.5 and IE6
IFrameDoc = IFrameObj.contentWindow.document;
} else if (IFrameObj.document) {
// For IE5
IFrameDoc = IFrameObj.document;
} else {
return true;
}

IFrameDoc.location.replace(URL);
return false;
}
 
 Top
Страниц (1): [1]
Сейчас эту тему просматривают: 0 (гостей: 0, зарегистрированных: 0)
« JavaScript & VBScript »


Все гости форума могут просматривать этот раздел.
Только зарегистрированные пользователи могут создавать новые темы в этом разделе.
Только зарегистрированные пользователи могут отвечать на сообщения в этом разделе.
 



Powered by PHP  Powered By MySQL  Powered by Nginx  Valid CSS  RSS

 
Powered by ExBB FM 1.0 RC1. InvisionExBB