Solved

How to get innerhtml from iframe from another web application

Posted on 2009-07-10
4
657 Views
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.

0
Comment
Question by:newexprt
[X]
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
4 Comments
 
LVL 3

Expert Comment

by:SordSord
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.

0
 
LVL 27

Accepted Solution

by:
rrz earned 125 total points
ID: 24828880
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
 
LVL 54

Expert Comment

by:b0lsc0tt
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.
b0lsc0tt
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Apache Camel - Unable to propagate JMS Header Properties between Request - Response 3 41
word0 challenge 3 120
maven example error 3 81
junit as external jar or library 7 58
This exercise is about for the following scenario: Dmgr and One node with 2 application server. Each application server contains it owns application. Application server name as follows server1 contains app1 server2 contains app1 Prereq…
There are numerous questions about how to setup an IBM HTTP Server to be administered from WebSphere Application Server administrative console. I do hope this article will wrap things up and become a reference for this task. You need three things…
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.

738 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