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
Форумы портала PHP.SU :: Версия для печати :: доступ к содержимому iframe
Форумы портала PHP.SU » Клиентская разработка » JavaScript & VBScript » доступ к содержимому iframe

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

1. dimalogin - 01 Июня, 2007 - 00:15:38 - перейти к сообщению
Здраствуйте, есть страница на которой есть
<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?
Спасибо.
2. evgenijj - 01 Июня, 2007 - 09:17:50 - перейти к сообщению
Цитата:

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
3. dimalogin - 01 Июня, 2007 - 21:59:59 - перейти к сообщению
Вот нашел Улыбка))))) Динамическое создание 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;
}

 

Powered by ExBB FM 1.0 RC1