How to get innerhtml from iframe from another web application

Posted on 2009-07-10
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 27

Accepted Solution

rrz earned 125 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

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

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

Verbose logging is used to diagnose garbage collector problems. By default, -verbose:gc output is written to either native_stderr.log or native_stdout.log.   It is also possible to redirect the logs to a user-specified file. This article will de…
A solution for Fortify Path Manipulation.
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.

624 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