Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to get innerhtml from iframe from another web application

Posted on 2009-07-10
Medium Priority
Last Modified: 2013-12-02
Hello Experts,

I manage multiple web-based database applications.
I'm trying to get data from one application and insert the data into another application on completely different domains/websites.

What I did is create an iframe on the destination application.  The iframe logs into the other application and grabs the data I want and displays the data as insert statements in the iframe.

I then have a Javascript on a button to attempt to get  the innerhtml of the body tag of the iframe.
When I try to do this I get an Access is denied.  I did some research on this and it's because the ifrmae is from a different domain than the destination application.

Does anyone have any suggestions on how I can do something like this?

Both applications use Tomcat and the applications are written in JSP.

Question by:newexprt
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 24825555
My suggestion would be to have the first application fetch the insert data directly from the second application. The first application can then either display the insert data on the result page for confirmation, or simply insert the data and display the final result.

If you need to display the confirmation page, I'd also have the application keep a copy of the inserts, so when the confirmation is returned, you won't need to parse the data from the page and it should eliminate any need for javascript.

Also, if you really need to solve this problem with javascript (which might be true if the two JSP applications can not talk to each other), it would be better asked in the javascript zone.

LVL 28

Accepted Solution

rrz earned 500 total points
ID: 24828880
I don't javascript will help you here. Your up againest the security issue. Look at
One app can make a request ( using a object or a JSTL import tag) to a servlet or a JSP in the other app.
LVL 54

Expert Comment

ID: 24829731
The expert above is right.  This won't work using ANY clientside script.  Browsers prevent it for security reasons like those that expert mentioned.  I just wanted to confirm this as a javascript expert.  All credit to the expert above for pointing out it can't be done.
You will have to use server script to get the contents from another domain.  If this page is on your server then an "AJAX" script could be used to load it in the page without reloading the whole page.  If this is done when the page loads then just have the main server script get the contents.  I am not a JSP expert but I am sure it has something like curl or WebClient that will let you "scrape" the contents from another site (i.e. make an http request to a URL and get the response).  A server page can do this without a security problem.  Of course make sure doing this doesn't violate the terms of use, etc from the other site. :)
If you have a question about this please let me know.

Featured Post

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most of the developers using Tomcat find it easy to configure the datasource in Server.xml and use the JNDI name in the code to get the connection.  So the default connection pool using DBCP (or any other framework) is made available and the life go…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question