/    Sign up×
Community /Pin to ProfileBookmark

Why doesn’t window.open work in this simple email validation script?

I have a simple email validation script. After email is validated the script writes a cookie, then opens a new window.

For the life of me I cannot figure out what why window.open will not work. (It works when I remove the cookie setting code. But not with it???).

What am I missing here?

[CODE]function emailCheck(emailStr) {
// checks if the e-mail address is valid
var emailPat = /^([A-Za-z0-9_-.])+@([A-Za-z0-9_-.])+.([A-Za-z]{2,4})$/;
var matchArray = emailStr.match(emailPat);
if (matchArray == null) {
alert(“Your email address seems incorrect. Please try again (check the ‘@’ and ‘.’s in the email address)”);
return false;
}
// make sure the IP address domain is valid
var IPArray = matchArray[2].match(/^[(d{1,3}).(d{1,3}).(d{1,3}).(d{1,3})]$/);
if (IPArray != null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert(“Destination IP address is invalid!”)
return false;
}
}
}

var email1 = document.email_capture.email.value;
var expires = new Date();
expires.setDate(expires.getDate() + 1825); // 1825 = days to expire
document.cookie = “email2= “+ escape(email1)+”; expires=”+ expires.toGMTString()+”; path=/; domain=localhost”;

window.open(“http://www.testing.com”, ‘_new’,’fullscreen=yes, scrollbars=auto’);

return true;
}
[/CODE]

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@Logic_AliMay 26.2013 — When that function returns [I]true, [/I]are you by any chance submitting a form?

If so then you are dismissing the document and all bets are off regarding what will and won't happen at that point.
Copy linkTweet thisAlerts:
@SageauthorMay 26.2013 — The javascript is triggered on an form onsubmit event. Yes the form is submitted.

Everything works, the cookie sets properly etc. WHEN the window.open statement is below the cookie code. When it is above the cookie code the window opens, but the cookie isn't set.

What would I need to change for the cookie to write, and the redirect to happen once the email passes validation?
Copy linkTweet thisAlerts:
@Logic_AliMay 26.2013 — Opening a window is not a good way to perform a redirect.

It should be handled by the form's target page.
Copy linkTweet thisAlerts:
@SageauthorMay 27.2013 — Understood. But there are several technical reasons why the form submissioin content needs to open in a new window, and needs to be a full size window.

The form redirect will not give us the function we need. We need a new window to open full size on form submission.
Copy linkTweet thisAlerts:
@SageauthorMay 29.2013 — UPDATE:

After a crap load of testing, I've discovered that the script works perfectly on a static HTML page. The error is only showing itself when the Javascript is run on a wordpress page.

Any ideas why?
×

Success!

Help @Sage 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.16,
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,
)...