A
A
AigizK2011-10-19 16:50:05
ActionScript
AigizK, 2011-10-19 16:50:05

Call js script from iframe?

There is a page site.ru/index.htm.
There is an iframe on this page, where a page from a subdomain is displayed, for example, this
[iframe src=' http://xxx.site.ru/index.htm'][/iframe ]
Like from a script that lies on the xxx.site page. ru/index.htm call a function that lies on the page site.ru/index.htm ?
Access to the source is available.

Answer the question

In order to leave comments, you need to log in

7 answer(s)
N
niko83, 2011-10-19
@niko83

Read this article dklab.ru/chicken/nablas/58.html at the end and don't forget to look at useful links.

A
Antimony, 2011-10-20
@Antimony

easyXDM solves such problems and, what is nice, is cross-browser.

T
TERMIK, 2011-10-19
@TERMIK

You can decide alternatively, i.e. read the result of executing this function from the desired page. Will this solution work for you? If yes, then I will write it to you.

T
TERMIK, 2011-10-19
@TERMIK

You write this script on the page where this function is executed:

T
TERMIK, 2011-10-19
@TERMIK

function getXmlHttp(){
var xmlhttp;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function getrec(set_any_result) {
var xmlhttp = getXmlHttp();
xmlhttp.open("GET", \' xxx.site.ru/index.htm?set_any_result='+set_any_result+'\');
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
window.parent.frames[1].document.close();
window.parent.frames[1].document.open();
window.parent.frames[1].document.write(xmlhttp.responseText);
}
}
xmlhttp.send();
}

A
AigizK, 2011-10-19
@AigizK

If the main page and the page from the iframe had the same domain, then it would be possible to call
window.top.needed();
But since in iframe we display a page from a subdomain, then this will not work.
But it turns out that this can be bypassed by changing the domain on the main page and on the iframe page and set the domain for both from the root site. Then js functions can be called like this
window.top.needed();
Read more here

T
TERMIK, 2011-10-19
@TERMIK

You can, however, use a less rational, but more understandable option. You can share the result with another page through invisible text fields. Well, for example, like this:
the main window is
the window with the text
the text of the named window

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question