Cross Domain Scripting

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    Cross Domain Scripting

    Is it possible to do Cross Domain Scripting in JavaScript.
    Basically i need to access some elements of an application from another application ..Is it possible to do using JavaScript?
    Please Help!
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    It is. You can use dynamic script tags which allow code form remote sites, e.g. JSON, to be included.

    You can also use a cross-domain proxy, but that depends on server-side code.

    For sub-domains, use the document.domain property.

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by acoder
      It is. You can use dynamic script tags which allow code form remote sites, e.g. JSON, to be included.

      You can also use a cross-domain proxy, but that depends on server-side code.

      For sub-domains, use the document.domain property.
      Can you give some related examples or any link where i can teach myself ..
      Thanks!

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        For what? All of the techniques or one particular one?

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          It would be better if you could give me all of the techniques ...
          Thanks!

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            The following links should be enough to get you started:
            JavaScript Developer Center : Use a Web Proxy for Cross-Domain XMLHttpRequest Calls - YDN
            Cross Domain Ajax: a Quick Summary - Snook.ca
            The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.

            Comment

            • dmjpro
              Top Contributor
              • Jan 2007
              • 2476

              #7
              What I need experts that ..... I have an application which contains some frames.
              Inside a frame there is a page from where i am trying to access some frames which is in another domain, placed in a frame of the previous application.
              Just i have to put a button by clicking i want to hide all of those frames...
              Now some frames are in one application and some in another application.
              So how do i access those frame or frameset properties from that application...?
              Please Help..Thanks!

              Comment

              • dmjpro
                Top Contributor
                • Jan 2007
                • 2476

                #8
                Thanks for your Help Acoder.
                But here i am not using any Ajax Call.
                And first two links are related to Ajax ...

                Comment

                • dmjpro
                  Top Contributor
                  • Jan 2007
                  • 2476

                  #9
                  Code:
                  function getFullScreen(){
                        var top_frameset = window.parent.document.getElementById('top_frameset');
                        var bottom_frameset = window.parent.document.getElementById('bottom_frameset');
                        
                        window.parent.top_frameset_rows = top_frameset.rows;
                        window.parent.bottom_frameset_cols = bottom_frameset.cols;
                       
                        var main_page = window.parent.frames['top_welcome'];
                        var main_page_framesets = main_page.document.getElementsByTagName('frameset');
                        
                        top_frameset.rows = "8%,*";
                        bottom_frameset.cols = "100%,*";
                        window.parent.frames['top_include'].location.href = "./temp_top_include.jsp";
                        if(main_page_framesets.length==0){
                            
                        }else if(main_page_framesets.length==1){
                          window.parent.main_page_cols = main_page_framesets[0].cols;
                          main_page_framesets[0].cols = "0%,*";
                        }else if(main_page_framesets.length==2){
                          window.parent.main_page_rows = main_page_framesets[0].rows;
                          window.parent.main_page_cols = main_page_framesets[1].cols;
                          main_page_framesets[0].rows = "0%,*";
                          main_page_framesets[1].cols = "0%,*";
                        }
                    }
                  This is my JavaScript code...

                  Code:
                  var main_page_framesets = main_page.document.getElementsByTagName('frameset');
                  This line gives me the error ..because top_welcome frame now contains the cross domain.
                  I think you get my point .... Please Help..Thanks!

                  Comment

                  • rnd me
                    Recognized Expert Contributor
                    • Jun 2007
                    • 427

                    #10
                    with fiefox and i think webkit nightlies, you can send cross-window messages.

                    more on that

                    for small-scale stuff, you can read jsnop from anywhere. if you can write json with ajax in one domain, it can be read from another.

                    you can also pass data cross domain using the query string (location.searc h), but this is more of a one-time thing, not useful for communicating actions, just data.

                    Comment

                    • dmjpro
                      Top Contributor
                      • Jan 2007
                      • 2476

                      #11
                      Is it for Firefox only, then what's for ...IE?

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        IE doesn't support it as yet. Although the proxy link describes how to do it with Ajax, you can always adapt it for your requirements. Do you have control over the other domain?

                        Comment

                        • dmjpro
                          Top Contributor
                          • Jan 2007
                          • 2476

                          #13
                          Yeah i have the control ... but Acoder ....for our application we are bypassing the Proxy. So can't we do this without using Proxy?

                          Comment

                          • acoder
                            Recognized Expert MVP
                            • Nov 2006
                            • 16032

                            #14
                            By proxy, I meant serving the page from the first domain, e.g. with PHP you could use Curl. Have a read of this to get an idea. However, since you have control of both domains, you can use something like this.

                            Comment

                            • dmjpro
                              Top Contributor
                              • Jan 2007
                              • 2476

                              #15
                              I could not figure out anything ...please could you show me some sample code ... :)

                              Comment

                              Working...