javascript rookie needs a close-window button

D

...D.

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.
 
Y

Yann-Erwan Perio

....D. said:
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 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:[email protected]" 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:[email protected]"
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.
 
R

Randy Webb

Andrew said:
On Fri, 17 Sep 2004 22:15:51 -0700, ...D. wrote:



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. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top