Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 660
  • Last Modified:

How to get innerhtml from iframe from another web application

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.

0
newexprt
Asked:
newexprt
1 Solution
 
SordSordCommented:
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.

0
 
rrzCommented:
I don't javascript will help you here. Your up againest the security issue. Look at  
http://en.wikipedia.org/wiki/Cross-site_scripting
One app can make a request ( using a java.net.HttpURLConnection object or a JSTL import tag) to a servlet or a JSP in the other app.
0
 
b0lsc0ttCommented:
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.
b0lsc0tt
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now