/    Sign up×
Community /Pin to ProfileBookmark

Control the focus after a submit

Hi All

I have a problem which has surfaced in IE8 and Firefox. I have a browser based application with some JavaScript and server objects controlled by ASP. The application ran fine in IE6 and IE7, we now want to move to IE8 and Firefox, other browsers will (unfortunately, and not my decision) be blocked.

I have used a technique where I submit a form for validation by the database, on return I may want to open a new window or refresh and pass the focus to an existing window. It would appear that in IE8 and Firefox if the window I want to pass the focus to is already open the focus will not be fully passed to it, but the window’s position on the task bar will flash. Oddly, this will not happen if the windows are being opened on the machine that hosts the application, making it harder to debug!

Code follows, any suggestions would be most welcome. I don’t think the contents of the window being opened (testfocus4.asp) are significant.

FG

Copy this code into a file called testfocus5.asp

<%
fFunction = request.form(“frmFunction”)
%>

<html>
<head>
<script LANGUAGE=”JavaScript”>

var wF2

function fTestFocus(){
document.f.frmFunction.value = “Test1”
document.f.submit();
}

function fTestFocus2(){
document.f.frmFunction.value = “Test2”
document.f.submit();
}

fFunction = “<% =fFunction %>”;

function init(){
document.f.test1.value = fFunction;
if (fFunction == “Test1”) {
var wTF4 = window.open(“TestFocus4.asp”,”TestFocus4″,””);
wTF4.focus();
}
else {
var wTF4 = window.open(“”,”TestFocus4″,””);
wTF4.focus();
}
}

window.onload=init;

</script>

</head>
<body>
<form name=”f” action=”TestFocus5.asp” method=”post”>
<input type=”hidden” name=”frmEdit”>
<input type=”hidden” name=”frmFunction”>
<input type=”text” name=”test1″ value=”0″>
<input type=”text” name=”fFunction” value=”<% =fFunction %>”>

<p>
<input type=”button” value=”Test1″ name=”TestButton1″ OnClick=”fTestFocus()”>&nbsp;&nbsp;&nbsp;&nbsp;
<input type=”button” value=”Test2″ name=”TestButton2″ OnClick=”fTestFocus2()”>&nbsp;&nbsp;&nbsp;&nbsp;
</p>
</form>

</body>
</html>

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @FG1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...