2

I am trying to click a link on another page(I do not have access to that page) which loads a JS function.

So can I call that function from my page thru a href="" or thru onClick=""

JS-Rockie
  • 25
  • 1
  • 4
  • Hi User, it helps us to better answer your question if you can show a more clear example of what you're trying to do. Consider posting a small example that helps to clarify your goals. Good luck! – jmort253 May 22 '12 at 05:01
  • i need to call a function which resides in an iframe on another page. Sorry - I cannot get clearer than this- :( – JS-Rockie May 22 '12 at 05:08
  • No worries, I think that helped! – jmort253 May 22 '12 at 05:19

2 Answers2

2

If it's on a different domain and you can't change its content, then you can't do it due to the same origin policy. Sorry. You'll have to find a different way to achieve whatever you're trying to do.

icktoofay
  • 117,602
  • 18
  • 233
  • 223
2

You can't call a function remotely from another page. Besides, you already left your page by then.

Unless...

  • that other page is somehow loaded to your page (AJAX+CORS or AJAX+proxy server maybe) and it's contents parsed on your page.

  • that other page has some logic that reads hashtags or query strings and executes corresponding functions. This could work inter-domain via iframes, as you are indirectly controlling the iframe via it's hash/query string.

  • that other page could be loaded via iframes. iframes would work if "I do not have access to that page" meant that you just don't have access on the current subdomain but both live on the same top domain.

    Subdomain iframe communications can work. Pages on example.com and subdomain.example.com can talk to each other but example1.com and example2.com can't talk to each other because both live on different domains. See the other answer regarding the Same Origin Policy.

Community
  • 1
  • 1
Joseph
  • 107,072
  • 27
  • 170
  • 214