Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Location Replace without bringing window to focus

Status
Not open for further replies.

JennL

Programmer
Sep 11, 2003
31
US
I am using a passthru page to determine what type of form to include(closed or open). I have to keep the 2 different forms since they access different tables, parameters, etc.

When I submit the form I use a new window as the target and want to replace the passthru page (order_lookup.asp) with the original lookup screen (_csinquiry.asp).

I was able to do that fine, but when I run the location.replace portion the passthru page comes into focus (with user input erased) until the page is replaced and the form post data is loaded. I made the fixWindows code part of the form submit but it had the same behavior.

I'd rather replace the location on order_lookup.asp without bringing the page into focus. I have no control over the new window since it's part of Business Objects XI. Does anyone know how to handle that from the passthru page? This is an intranet site so we have a captive audience of IE 5.5+ users...

My code as it stands now:

FORM TAG (could be vwClosedOrder too)
Code:
<form name="vwOrderOpen" method="post" action="/authBOXIViewer/View_CR_Report.aspx" target="newWin">

BODY TAG
Code:
<body onLoad="chkAutoSub()" onBlur="fixWindows()">


SUBMIT CODE
Code:
function chkAutoSub(){
	if (frmAutoSub == "closed") {
		document.forms["vwOrderClosed"].elements["vParam-CUST_NO"].value = sCustNo;
		document.forms["vwOrderClosed"].elements["vParam-SHIP_TO"].value = sShipTo;
		document.forms["vwOrderClosed"].elements["vParam-DOC_NO_ALPHA"].value = sDocNo;
		newWin=window.open('','newWin','');
		document.vwOrderClosed.submit();
	} else if (frmAutoSub == "open"){
		document.forms["vwOrderOpen"].elements["vParam-CUST_NO"].value = sCustNo;
		document.forms["vwOrderOpen"].elements["vParam-ORD_NO"].value = sOrdNo;
		newWin=window.open('','newWin','');
		document.vwOrderOpen.submit();
	}
}
function fixWindows(){
		window.location.replace("_csinquiry.asp");
		window.newWin.focus();
}
 
Here's two possible solutions:

1. Put an onload handler in the popup, which waits 2 seconds (or maybe less), and then focusses itself, or

2. Open the window with a known name, and when the file _csinquiry.asp has loaded, re-open the popup with the same name.

I'd go for option 1, unless the popup reloading isn't an issue for you.

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Dan,
I don't think either option would work in my situation. The "popup" is actually a crystal report rendered through a third party object which I can't access the code on... If I try to re-open it I would have to resubmit the form and be caught in the same loop.

I will mention your suggestion to the 3rd party and see if they have a way around this. Thanks for your insight!
Jenn
 
Here is a demo of how I think can be done without being clouded by some specific things we don't have accessed to to look clear. (Or, I miss the point.)

A page x_caller is loaded. A user can then decide which form to fill in, x_form1 and x_form2 pages. Once the x_form1 or x_form2 is called it will be loaded always to the same window. The user will then fill in and submit. The action page y_action will be loaded to a new window (y) and the opener window---the original will be replaced by the original caller page x_caller. The focus aspect is that the new window (y) will be on focus where as the original x_caller page window will be on the background.
[tt]
|-- x_form1 --|
x_caller-->-| |-->- x_caller (out of focus)
|-- x_form2 --|
|
|------>---------y_action (in focus)
[/tt]
Since y_action is generated by some application and out of control is taken into account. Nothing is scripted into it to interact with the x_ pages.

The running of it seems give you the desired effect.
Code:
<!-- x_caller -->
<html>
<head><title>x_caller</title>
</head>
<body>
<p>If this condition is satisfied, call this submission form.</p>
<button onclick="window.location='s03_form1.htm'">load s03_form1</button>
<p>If that condition is satisfied, call that submission form.</p>
<button onclick="window.location='s03_form2.htm'">load s04_form2</button>
</body>
</html>
Code:
<!-- x_form1 -->
<html>
<head><title>x_form1</title>
<script language="javascript">
var y;
function doit() {
	if (y){
		// alert(y.name);	//newwindow - testing
	} else {
		y=new Object;
		y.name="newwindow"
		document.forms[0].target=y.name;
	}
	window.location.replace("s03_caller.htm");
	return true;
}
function checkit() {
	if (y) { alert(y.name); }
}
function setfocus() {
	if (y) { y.focus(); }
}
</script>
</head>
<body onload="checkit()" onunload="setfocus()">
<form action="y_action.htm" method="post" onsubmit="return doit()">
<input type="text" name="custno" /><br />
<input type="text" name="shipto" /><br />
<input type="text" name="doc" /><br />
<input type="submit" name="tosubmit"  /><br />
</form>
</body>
</html>
Code:
<!-- x_form2 -->
<html>
<head><title>x_form1</title>
<script language="javascript">
var y;
function doit() {
	if (y){
		// alert(y.name);	//newwindow - testing
	} else {
		y=new Object;
		y.name="newwindow"
		document.forms[0].target=y.name;
	}
	window.location.replace("s03_caller.htm");
	return true;
}
function checkit() {
	if (y) { alert(y.name); }
}
function setfocus() {
	if (y) { y.focus(); }
}
</script>
</head>
<body onload="checkit()" onunload="setfocus()">
<form action="y_action.htm" method="post" onsubmit="return doit()">
<input type="text" name="custno2" /><br />
<input type="text" name="shipto2" /><br />
<input type="submit" name="tosubmit"  /><br />
</form>
</body>
</html>
Code:
<!-- y_form2 -->
<html>
<head><title>y_form2</title>
<script language="javascript">
function checkit() { //this is just for testing --- a page out of control in principle
	//alert(window.name);	
}
</script>
</head>
<body onload="checkit()">
This is the action page, loaded to window y.
</body>
</html>
- tsuji
 
Amendment:

Replace any where referring to pages like s03_ by x_. It is a trace of my testing config. (I should have cleaned up the mess a bit before posting.)

- tsuji
 
Tsuji,
I'm working with your code and getting an error that y.focus() is unsupported. Did it work for you?
Jenn
 
Jenn,

Sorry for the dirt left behind inside the script. I try relist lines that are left with some trace I was testing. They should be immaterial.

[1] x_caller.htm
>[tt]<button onclick="window.location='s03_form1.htm'">load s03_form1</button>
<button onclick="window.location='[blue]x_form1.htm[/blue]'">load [blue]x_form1[/blue]</button>[/tt]

>[tt]<button onclick="window.location='s03_form2.htm'">load s04_form2</button>
<button onclick="window.location='[blue]x_form2.htm[/blue]'">load [blue]x_form2[/blue]</button>[/tt]

[2] x_form1 and x_form2.htm
>[tt]window.location.replace("s03_caller.htm");
window.location.replace("[blue]x_caller.htm[/blue]");[/tt]

[3] The rest are just at <!-- x_caller -->, <!-- x_form1 -->, <!-- x_form2 --> and <!-- y_action --> and inside the <title> tag. The above four are the htm page name with extension .htm for the demo, ie, x_caller.htm, x_form1.htm, x_form2.htm and y_action.htm.

I do not get error from the browser.

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top