Answer the question
In order to leave comments, you need to log in
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
Read this article dklab.ru/chicken/nablas/58.html at the end and don't forget to look at useful links.
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.
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();
}
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question