By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,336 Members | 2,307 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,336 IT Pros & Developers. It's quick & easy.

javascript rookie needs a close-window button

P: n/a
OK. I am halfway decent with HTML. Now I want to try javascript for some
things that HTML cannot do. I have looked over a tutorial & all.

What I want to do is create a button, that when pressed, closes the window
it is in, and launches a URL. The window the button is in is actually just
a sub-page of the main website page, launched with target="blank", but I
just do not want to close the window as I said, I want to launch a website
address from it & have the launched from window close.

So please, walk me through this. Where do I place the:

<SCRIPT language="JavaScript"> ?

(Oh - this is thr right way, correct - case sensitive, right?)

Then what? I can create a button with the tutorials, but if you know, just
write the darned thing for me please - I learned HTML mostly from
copy/pasting.

AND... OK, now more complicated maybe (???). Actually this is more
important than the above. This is from an application sub-page, the page
opening with target="_blank". So the below is HTML that creates buttons.
If the applicant presses the "submit application" button, at least when I
press it, it launches O.E. and asks me if I want to send the filled-in text
through O.E. to the email recipient. You know what I mean, right ? Well,
I want the window the "submit application" button is in to do it's thing all
right - submitting through the email, but I also want the page or window
(I.E. or other?) launched from to close also.

------------ the HTML code that shows two buttons:

<input type="submit" value="submit application">
<input type="reset" value="start over"/><br>

Thanks for your input. Assume I know nothing about javascript, but can get
around in HTML.

...D.
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
....D. wrote:
What I want to do is create a button, that when pressed, closes the window
it is in, and launches a URL. The window the button is in is actually just
a sub-page of the main website page, launched with target="blank", but I
just do not want to close the window as I said, I want to launch a website
address from it & have the launched from window close.
In the popup, you can refer to the opener window with the property
"opener"; before closing your popup, you just have to set the
location.href property of the opener to the new location.

Add the following in your popup:

---
<script type="text/javascript">
//write the close button
//but only if it can be used successfully
if(opener && self.close) {
document.write(
"<input type='button' "+
"value='Close' "+
"onclick='"+
"opener.location.href=\"http://jibbering.com/faq/\";"+
"self.close();"+
"'"+
">"
);
}
</script>
---
<SCRIPT language="JavaScript"> ?

(Oh - this is thr right way, correct - case sensitive, right?)
Javascript is indeed case-sensitive, however the HTML attribute language
is not - and it's actually deprecated, so don't use it, use
type="text/javascript" instead.
If the applicant presses the "submit application" button, at least when I
press it, it launches O.E. and asks me if I want to send the filled-in text
through O.E. to the email recipient.


That's just a "mailto:us**@domain.com" action for the form. However the
technique changes a bit from above:

---
<script type="text/javascript">
function validate(frm){
if(opener) {
opener.location.href="http://jibbering.com/faq/";
}
if(window.close) {
setTimeout("window.close()",1);
}
return true;
}
</script>

<form action="mailto:fo*@bar.com"
onsubmit="return validate(this)">
<input type="text" name="foo">
<input type="submit">
</form>
---

Note that the techniques exposed, while maybe acceptable for a personal
website, would not be used for a commercial one, since they have too
many inherent flaws:
- they rely on popup window, which can be affected by popup-blocking
software,
- they rely on mailto:, assuming that the user has a mail agent
configured (which is not always the case, many people just use web-based
mail agents) - ideally the mail should be built and sent server-side
(google for formmail).
HTH
Yep.
Jul 23 '05 #2

P: n/a
On Fri, 17 Sep 2004 22:15:51 -0700, ...D. wrote:
OK. I am halfway decent with HTML. Now I want to try javascript for some
things that HTML cannot do.
Really? What things?
..I have looked over a tutorial & all.
Well, you have put in the hard yards..
Did you *read* *it*, or just glance
over it?
What I want to do is create a button, that when pressed, closes the window
it is in, and launches a URL.
Pop-Ups.. Your app. is already sunk.

They do work, OK, in some browsers, but
whoever deploys such broken methods must
take special pains to explain to browsers
why your links are not doing anything in
there wonderfully current and up to date
IE with SP 2.

.... So please, walk me through this. Where do I place the:

<SCRIPT language="JavaScript"> ?
Somewhere late last millennium.
<script type='text/javascript'>

You can define functions in the <head>
and call them in the <body>. Actually
you can define methods all over the place,
but it makles most sense to collect them
in one place, either in the <head>, or
in an external file.
(Oh - this is thr right way, correct - case sensitive, right?)


No. JS is generally not case sensitive.

Now, ..given I've been up 28 hours, I better
leave the important stuff for the gurus.

Over and ..snore..

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
Jul 23 '05 #3

P: n/a
Andrew Thompson wrote:
On Fri, 17 Sep 2004 22:15:51 -0700, ...D. wrote:


<--snip-->
(Oh - this is thr right way, correct - case sensitive, right?)

No. JS is generally not case sensitive.

Now, ..given I've been up 28 hours, I better
leave the important stuff for the gurus.


Blame it on the lack of sleep. JS is very case-sensitive. Its the HTML
tags that are not. :-)
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #4

P: n/a
On Sat, 18 Sep 2004 14:04:48 -0400, Randy Webb wrote:
No. JS is generally not case sensitive.
... ..JS is very case-sensitive. Its the HTML
tags that are not. :-)


Aha! Thank you. Personally I allways
use correct case with JS commands (as
well as I understand the nomenclature)
and string comparisons, for the simple
reason it becomes easier for me to read.

Lucky for me (and the OP) you were paying
attention. ;-)

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.lensescapes.com/ Images that escape the mundane
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.