i want to call a javascript function on another webpage. So far, my solution is to create a page with an iframe containing the target page.
<a onclick="func1()">Call</a>
<script type="text/javascript">
function func1()
{
document.getElementById('myFrame').contentWindow.some_function();
}
</script>
<iframe id="myFrame" src="http://www.webpage.com">
Problem is, that this solution only works when both pages have the same domain. Otherwise, i am getting this error:
Uncaught SecurityError: Blocked a frame with origin "http://my_webpage.com" from accessing a frame with origin "http://not_my_webpage.com". Protocols, domains, and ports must match.
I have googled for hours, but i have only found that i need to use
document.domain = document.domain;
After using it, i get this error:
Uncaught SecurityError: Blocked a frame with origin "http://my_webpage.com" from accessing a frame with origin "http://not_my_webpage.com". The frame requesting access set "document.domain" to "http://my_webpage.com", but the frame being accessed did not. Both must set "document.domain" to the same value to allow access.
I guess that i need to use it on both pages, but the page in iframe isn't mine and i don't have acces to it. Any ideas? Thanx.