is it possible to communicate with another domain javascript function using ajax

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pankaj17
    New Member
    • Nov 2008
    • 7

    is it possible to communicate with another domain javascript function using ajax

    hello,

    Is it possible to communicate with another domain javascript function using ajax.
    Suppose i have a iframe and domain is different and in the iframe i have some links. If user clicks on that link i want to call javascript function written in main page (not in iframe). is this possible using ajax to call the java script function of another domain.
    if possible please tell me the example.
    if not please tell me the another way.

    please help me out............ ...

    Thanks in advance.
  • rnd me
    Recognized Expert Contributor
    • Jun 2007
    • 427

    #2
    not possible.

    you will have to use a "proxy" for your server that can fetch page from other domains and re-broadcast them from your server. only if if the pages are on the same server can a click action be passed like that.

    Comment

    • pankaj17
      New Member
      • Nov 2008
      • 7

      #3
      the two frames can communicate with each other by using fragment identifiers (the hash part of an URL, like http:// some.domain.com/path/to/page.html#fragm entIdentifier).

      some thing like that is possible using ajax please let me know........... ..

      Comment

      • xNephilimx
        Recognized Expert New Member
        • Jun 2007
        • 213

        #4
        Originally posted by pankaj17
        the two frames can communicate with each other by using fragment identifiers (the hash part of an URL, like http:// some.domain.com/path/to/page.html#fragm entIdentifier).

        some thing like that is possible using ajax please let me know........... ..
        that's true. You can also use a hidden iframe, and access it with js, or you can use curl (in php or any server side language) to get the content from another domain, and then ajax to query the script that makes the curl petition.

        Comment

        • rnd me
          Recognized Expert Contributor
          • Jun 2007
          • 427

          #5
          Originally posted by pankaj17
          the two frames can communicate with each other by using fragment identifiers (the hash part of an URL.
          while that can be used to pass data, it will not allow a page to invoke a function on the parent page, the original question.

          Comment

          • xNephilimx
            Recognized Expert New Member
            • Jun 2007
            • 213

            #6
            Originally posted by rnd me
            while that can be used to pass data, it will not allow a page to invoke a function on the parent page, the original question.
            I'm not completely sure, but can't you call a function in the parent window with window.parent.f unc_name ?
            Correct me if 'm wrong, because I'm not sure.

            Comment

            • rnd me
              Recognized Expert Contributor
              • Jun 2007
              • 427

              #7
              Originally posted by xNephilimx
              I'm not completely sure, but can't you call a function in the parent window with window.parent.f unc_name ?
              Correct me if 'm wrong, because I'm not sure.
              you can in the same domain.
              the object property is there in other domains, but accessing it will raise an exception unless security policies have been altered in some fashion.

              this is the case in all browsers by design, save some old IE versions that accidentally let some things slip.

              Comment

              • xNephilimx
                Recognized Expert New Member
                • Jun 2007
                • 213

                #8
                Originally posted by rnd me
                you can in the same domain.
                the object property is there in other domains, but accessing it will raise an exception unless security policies have been altered in some fashion.

                this is the case in all browsers by design, save some old IE versions that accidentally let some things slip.
                Thanks, rnd_me! I didn´t know that, never tried it.

                Maybe, pankaj17, you can set event listeners in the iframe's content, getting the iframe document element and checking for it's ready state using jquery, then adding the listeners. Don't know about security exceptions that may raise though, I should try.

                Comment

                • rnd me
                  Recognized Expert Contributor
                  • Jun 2007
                  • 427

                  #9
                  Originally posted by xNephilimx
                  Thanks, rnd_me! I didn´t know that, never tried it.

                  Maybe, pankaj17, you can set event listeners in the iframe's content, getting the iframe document element and checking for it's ready state using jquery, then adding the listeners. Don't know about security exceptions that may raise though, I should try.
                  you aren't allowed to reach the document.

                  i have seen this link, and been meaning to try it.

                  let me know if anyone has any luck.

                  Comment

                  Working...