Re: Transfer javascript code from iFrame to a DIV
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Transfer javascript code from iFrame to a DIV

From: <sameergn@gmail.com>
Date: Sat Apr 29 2006 - 21:02:41 CEST

Thanks all of you for your replies.
Our architect suggested a simple solution. We added following code in
the JSP that loads in the IFrame

<script language="javascript">
    AddUserController = function() {
       this.validate = function(formObj) {
            // validation code
       }
    }
    window.parent.document.addUserController = new AddUserController()
;
</script>

 This add a Javascript object called addUserController in the parent
document and then
 The code loaded in IFrame can use addUserController to call functions
like validate().

 <script language="javascript">
        window.parent.getIFrameData();
 </script>

 getIFrameData() is defined in parent document.
 function getIFrameData()
 {
document.getElementById("mainDiv").innerHTML =
test_iframe.document.body.innerHTML;
} // getIFrameData().

 We initially were using DWR, but it allows accessing only POJOs
through AJAX and
 we wanted to call just the JSP. We found that DWR uses same IFrame
mechanism
 if posting method is IFrame instead of XMLHttpRequest (but still posts
to POJO).
 Is there any recommended,well tested AJAX library that can be used
here to post to
 any URLs?

 Thanks,
 Sameer
Received on Mon May 1 05:27:02 2006