/    Sign up×
Community /Pin to ProfileBookmark

Closing a window

Hi, I need to close active window but before I do that I validate the data.

[code]
function validateForm()
{
var date1=document.getElementById(“date_month”).value;
var hour1=document.getElementById(“hour”).value;
var min1=document.getElementById(“min”).value;
var ampm=document.getElementById(“ampm”).value;
var error=””;

if (date1==””)
error+=”Please select a date !n”;
if (hour1==””)
error+=”Please select a hour !n”;
if (min1==””)
error+=”Please select a minutes !n”;
if (ampm==””)
error+=”Please select a AM/PM identifier !n”;
if (error!=””) {
alert (error);
return false;
} else {
window.close();
return true;
}
}
[/code]

My function stops working on

[CODE]window.close(); [/CODE]

statement. It’s like I have syntax error there. I need to make it work in IE 5.0 .

What am I doing wrong?

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@SelrachDec 15.2005 — window.close() doesn't work unless the window itself was opened by a script.

What browser are you targeting and is it a popup?
Copy linkTweet thisAlerts:
@SelrachDec 15.2005 — There is a workaround for IE, but I'm not sure if I can post it because technically it is a security risk. If you google for it I'm sure its around.
Copy linkTweet thisAlerts:
@difrad76authorDec 15.2005 — The window was opened by the script on the different page.

function cbTracker()

{

var res="CB";

if (res=='CB') {

var SpecsWindow = window.open("../CB_TRACKER/cb.jsp","cbTracker","width=350,height=200");

SpecsWindow.focus();

}

}
Copy linkTweet thisAlerts:
@SelrachDec 15.2005 — Though this should not matter, since both commands are effectively the same replace

window.close(); -> self.close();

I don't see any syntax errors so if that doesn't work then i'm sorry I don't think i can help
Copy linkTweet thisAlerts:
@difrad76authorDec 15.2005 — This window.close(); statement does work in IE 6 but doesn't in IE 5.0. How can I make it work in IE 5.0 ?
×

Success!

Help @difrad76 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 6.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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...