/    Sign up×
Community /Pin to ProfileBookmark

auto close a Popup Window

Hi guys,
Bit of a newbie here, Just wondering if anyone could help me out here.
when i click on a image it opens pop-up and plays a mp3 file (it doesn’t open a html page) and then i want to close it after ‘x’ seconds. Now, I’ve tried the setTimeout function but haven’t seemed to get it to work.
Any suggestions???
code so far:

<script type=”text/javascript”>
function PopWin(urlName) {
var popup = window.open(“”, “”,width=10,height=10);
popup.location = urlName;
var file = urlname;
}

</script>

</head>

<body>
<a href=”javascript?opWin(‘mp3file.mp3’)”><img src=”1.JPG” width=”192″ height=”216″ border=”0″>

Thanks

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@Mr_JJul 20.2008 — Give this a try

[CODE]function PopWin(urlName) {

var popup = window.open(urlName, "",'width=100,height=100');

setTimeout(function(){popup.close()},2000)
}[/CODE]
Copy linkTweet thisAlerts:
@Kiwi_cowboyauthorJul 20.2008 — Thanks Mr J, Worked a treat
Copy linkTweet thisAlerts:
@donatelloJul 20.2008 — Give this a try

[CODE]function PopWin(urlName) {

var popup = window.open(urlName, "",'width=100,height=100');

setTimeout(function(){popup.close()},2000)
}[/CODE]
[/QUOTE]


Hmmmm... I can use that one!

I also have a "close window" button in mine.

[CODE]<INPUT type="button" value="Close Window" onClick="window.close()">[/CODE]
Copy linkTweet thisAlerts:
@Kiwi_cowboyauthorJul 21.2008 — ok, so if i want to redirect the parent page to a different html file, where do i put that, i tried putting this in:

function PopWin(urlName)

{

var popup = window.open(urlName, "",'width=10,height=10');

opener.window.location.href="2.html";

setTimeout(function(){popup.close()},6000)

}

but didn't work...
Copy linkTweet thisAlerts:
@Mr_JJul 21.2008 — Try it this way

[CODE]function PopWin(urlName) {

var popup = window.open(urlName, "",'width=100,height=100');

setTimeout(
function(){
popup.close()
window.location="page2.htm"
}
,2000)
}[/CODE]
Copy linkTweet thisAlerts:
@Kiwi_cowboyauthorJul 21.2008 — Yay, thank you :-)

i did have to put a colon in between the popup.close() and the window.location like this:

setTimeout(function(){popup.close();window.location="2.html"},5500)

Thank you :-)
Copy linkTweet thisAlerts:
@donatelloJul 23.2008 — Hey guys, thanks a lot for all of that. I got it working on my site where I need a popup to open that contains a PHP script to delete the contents of log files.

I'm using this script in my Admin panel, where the logs appear in iFrames. The button will open a popup which deletes the log, then automatically closes after 2 seconds - it displays the message: "Logs Reset". Then the original page refreshes to show the empty iframes.

Very cool now! For anyone else following the thread, I'll post the entire script that works - I had to add a semicolon for it to work.


[CODE]
<head>
<!--Test of Pop Window Script BEGIN-->
<!--Open a popup window and close it in 2 seconds-->
<script type="text/javascript">
function PopWin(urlName) {
var popup = window.open(urlName, "",'width=200,height=100');
setTimeout(function(){
popup.close();
window.location="admin.php"
}
,2000)
}
</script>
</head>

<body>
<!--Opening the popup, erasing the logs and resetting the page with a button-->
<FORM>
<INPUT type="button" value="Reset ALL Log Files" onClick="javascript:PopWin('reset_all.php')" title="This will erase all logs and refresh this page.">
</FORM>

<!--Test of Pop Window Script END-->
[/CODE]
×

Success!

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