Refresh Parent Window From iFrame Pop-up - java

I have an HTML page (index.htm) and a link in it. Clicking on that link opens a ColorBox iFrame (popup.htm) its a form with submit button.
Now when someone submits the form in that popup.htm page, I need index.htm to refresh automatically to -> index2.htm.
I have tried this and variations with no success.
<form onsubmit="window.opener.location = 'http://www.myDomain.com/index2.htm';">

Did you try <form onsubmit="window.top.location.href = 'http://www.myDomain.com/index2.htm';"> Of course iframe and top must be on same domain and don't break same origin policy.

Related

JasperReports on new tab

I'm a newbie here and I would like to consult something regarding JasperReports and servlets.
I have a form called appform.jsp which is an application page.
What I want to achieve is that when I click the Submit button of the application page, a new tab will open then a PDF file will be displayed.
The submit button calls the sevlet that will generate the pdf then the PDF will be displayed in a new tab.
I wonder if this line is correct
<input type="submit" value="Submit" onClick="validateForm(); openinnewtab('<%=request.getContextPath()+"/readFields"%>')" >
validateForm() is just a javascript checker for empty fields, readFields is my servlet and my form's onsubmit tag is on return false;
Thank you.
give target="_blank" in the form tag. some browsers open a page some a tag . you can also try target="_new" using this you can easily open new tab

Scraping an aspx site with HtmlUnit, how does one click on a Javascript button?

I'm attempting to scrape an .aspx site, which is a essentially just a big paginated table along the lines of the one found here: http://data.fingal.ie/ViewDataSets/ (Note, the actual site I'm scraping is behind a paywall, so can't post the actual link ).
However, the problem is that rather than each page of the table having a unique url, the table changes pages by posting to itself, and then updating the content inside of the table.
The next page button looks like this:
</td>
<td class="dxpButton" onclick="aspxGVPagerOnClick('ctl00_cphProduct_gvList','PBN');" style="cursor:pointer;">
<img class="dxWeb_pNext" src="/DXR.axd?r=1_5-BUdv6" alt="Next" /></td><td style="width:4px;"><div style="height:1px;width:4px;overflow:hidden;">
How would I simulate a click on this button using HtmlUnit?
You would want to find the <div class="dxpButton">.
The easiest way of doing this would be using xPath:
final WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage("http://<<YOUR URL HERE>>");
final HtmlDivision div = page.getFirstByXPath("//div[#class='dpxButton']");
page = div.click();
// This returns the page shown after the click
This will perform the click. I assume that it is loaded through AJAX, in which case you may want to use:
while(some new element doesn't exist; or some 'completed' condition) {
// Wait for javascript to catch up.
webClient. waitForBackgroundJavaScript(1000);
}

HtmlUnit webscraping Anchor tag with dropdown link that has JavaScript

Is it possible to click on a link using HtmlUnit when that link has a dropdown list of links when you mouseover the initial link. If you click the initial link nothing happens except for you get list of links that drop down when you mouse over. I would like to click one of the drop down links and grab the web page that is associated with that link.
The problem seems to be that the Anchor has JavaScript and also it is a drop down list. If the Anchor did not have JavaScript and drop down then I would not have any problems.
Here is the pertinent JavaScript Code:
<script language='JavaScript' type='text/javascript'>
<!--
function mmLoadMenus(){
window.mm_menu_0805151542_0 = new Menu("root",211,23,"Arial, Helvetica, sans-serif",11,"#FFFFFF","#FFFFFF","#056CB9","#014D98","left","middle",3,0,1000,-5,7,true,false,true,2,true,false);
mm_menu_0805151542_0.addMenuItem("View Tax Sales","window.open('TCTaxSaleBrief.asp', '_blank','width=800,height=580,scrollbars=1,resizable=yes,top=50,left=100');");
mm_menu_0805151542_0.addMenuItem("Registration Renewal Reprint","window.open('vrRenewal.asp', '_blank','width=800,height=580,scrollbars=1,resizable=yes,top=50,left=100');");
mm_menu_0805151542_0.addMenuItem("Drivers License","window.open('http://www.dds.ga.gov/', '_blank');");
mm_menu_0805151542_0.addMenuItem("Online Tag Renewals","location='../TaxCommissioner/TagRenewal.html'");
mm_menu_0805151542_0.hideOnMouseOut=true;
mm_menu_0805151542_0.bgColor='#CCCCCC';
mm_menu_0805151542_0.menuBorder=0;
mm_menu_0805151542_0.menuLiteBgColor='#FFFFFF';
mm_menu_0805151542_0.menuBorderBgColor='#015BA7';
</script>
Here is the pertinent Anchor:
Online Services<br />
Here is the snippet of Java Code that I am using to make this work.
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_10);
String webPage="http://website.html";
try {
HtmlPage taxComPage = webClient.getPage(webPage);
HtmlElement htmlElement = taxComPage.getDocumentElement();
//HtmlAnchor anchor = taxComPage.getAnchorByText("View Tax Sales");
//HtmlAnchor htmlAnchor = taxComPage.getHtmlElementById("link10");
HtmlAnchor anchor = taxComPage.getAnchorByText("Online Services");
HtmlPage page = anchor.click();
}catch
If it is the case that HtmlUnit does not work with JavaScript please let me know!
Thanks
I understand that there is this function called: mmLoadMenus() which has text that is displayed when moused over but I having issue with how is this function associated with the anchor. In the anchor there is something called MM_showMenu. What is this MM_showMenu, who created it, is this a JavaScript keyword, I don't see it being defined anywhere. I have searched the whole page, the only place it is mentioned is in the anchor. It seems to be some type of a function with parameters of: window.mm_menu_0805151542_0,104,0,null,'link11' being passed to it. The only connection that I can make between function mmLoadMenus() and the anchor is that the anchor has mm_menu_0805151542_0 in it. I am not that well versed in JavaScript maybe that is why I am not making a strong connection with the JavaScript function and the anchor.
The data is already on the page so why not scrape it from the JavaScript function itself. Just a matter of parsing out the text - much easier then trying to force it to load.

Update iframe in container page on submit of <form> in container page

I have a main html page which contains an IFRAME.
I have a server side jsp code that is displayed with some default values inside the IFRAME for the first time.
Whenever a person tries to use a search button in the main page the results are displayed in the IFRAME updating its content.
I have a servlet that does the calculation on the searched data and updates the IFRAME content.
The problem:
I have used the sendRedirect method in servlet to refresh the IFRAME but to no avail.
The string I am passing to sendRedirect is /results.jsp?search=value&size=1 (jsp to be displayed in iframe).
The servlet does its calculation work properly but opens a new page in place of the mainpage: not a desired output.
The mainpage with its interface should remain there, only the IFRAME should refresh.
My question:
Is this the correct method to refresh an iframe? If not kindly tell me what should I use to update my iframe (jsp) via servlet.
PS: Please forgive the absurdity of the quesion if any. I am new to the jsp-servlet.
Any help is much appreciated
When you do a redirect using response.sendRedirect() method, the actual 'frame' where the servlet was called will be modified. That frame can be the entire page, or an iframe, or even the legacy frames used in javadocs.
As #Jake223 said, set the target attribute to the iframe name in the form:
If you are using a form to submit the information, then you do something like this:
<iframe name="resultframe"></iframe>
<form action=[path to servlet] target="resultframe">
<input type="text" name="searchq"/>
<input type="submit" value="search"/>
</form>
If you are using javascript to create the iframe, then use the src attribute of the iframe:
<iframe src=[path to servlet]?[request params]></iframe>
If the search mechanism is an HTML form, you can set the target attribute of the form to the name of the iframe in question. See W3Schools's page on this for more details.

Display page data on same page without forwarding it to another page

In my webpage (Eg Link1: http://localhost:8086/MyStrutsApp/login.do) I have several links. When a user clicks on one of the links, he is taken to another page (Eg link2: http://localhost:8086/MyStrutsApp/AddBook.jsp) to fill an html form.
Now what I want to achieve is that when any user clicks on the link, that html form (Link2) is displayed on the same page (i.e. Link1).
I have no idea how to achieve this.
The AJAX way to achieve this is the following:
you have a DIV on your original page that will be replaced (i.e., either has content that only makes sense in the original context or completely empty)
your Link2 servlet produces only the contents of the above DIV (and not the contents of that page)
you use a tiny bit of Javascript to make an AJAX call and fill the DIV with the response.
If you want to use Dojo, the HTML page would look like this:
<!-- main content -->
<div id="leftpanel">
<h3>This content will be replaced</h3>
You can add a book
</div>
The Javascript code would look like this:
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/dojo.xd.js" type="text/javascript"></script>
<script type="text/javascript">
function display_wait(s) {
var mainPanel=dojo.byId("leftpanel");
mainPanel.innerHTML='<div class="waitingmsg">'+s+'</div>';
}
function updateFromURL(url) {
display_wait("loading content");
dojo.xhrGet({url:url,
load:function(result) {
dojo.byId('leftpanel').innerHTML=result;
}});
}
</script>
(As Rafa mentioned, you can use the same technique to display the new part in a dialog)
You can always use jQuery to present a dialog ... http://jqueryui.com/demos/dialog/
Retrieve the page with AJAX and present it inside the dialog.
To display one page within another, use an iframe. See the iframe docs.
To make a link on the outer page load its target page into the iframe, give the iframe a name attribute, and give the link a matching target attribute.

Categories

Resources