Page 1 of 1

Same button to download and open a different URL

Posted: Mon Dec 04, 2006 9:37 am
by Maluendaster
Can someone share a code to open a new window, but at the same time it has to redirect (not the open window) to a file.... I had it but i formated my PC.. And i cant remember how it's done..

thank you.

Posted: Mon Dec 04, 2006 9:51 am
by Corvin
You have to use JavaScript for that. Check the JS-Code of a website where this functionality is used.

Posted: Mon Dec 04, 2006 10:32 pm
by Maluendaster
do you know where i can find a site using that???

Re: Same button to download and open a different URL

Posted: Mon Dec 04, 2006 10:47 pm
by Maluendaster
Maluendaster wrote:Can someone share a code to open a new window, but at the same time it has to redirect (not the open window) to a file.... I had it but i formated my PC.. And i cant remember how it's done..

thank you.
ah! i forgot to ask how to make a "countdown" , for example,

Wait 15 seconds to download the file

and after 15 seconds, the download link will appear...

I want to do this without a DB

Posted: Mon Dec 04, 2006 11:01 pm
by Zoxive
Before You Ask

Before asking a technical question by e-mail, or in a newsgroup, or on a website chat board, do the following:

1. Try to find an answer by searching the archives of the forum you plan to post to.
2. Try to find an answer by searching the Web.
3. Try to find an answer by reading the manual.
4. Try to find an answer by reading a FAQ.
5. Try to find an answer by inspection or experimentation.
6. Try to find an answer by asking a skilled friend.
7. If you're a programmer, try to find an answer by reading the source code.
#1

Code: Select all

<script type="text/javascript">
function open_window(){
	// Whatever popup window code you want to use...
	window.open("http://www.devnetwork.net","Devnetwork");
	// Link to File to Download or Page to go to
	document.location = 'http://www.google.com';
}
</script>

<a href="javascript:open_window();">Test</a>
#2

Code: Select all

<html>
<head>
<script type="text/javascript">
function show_download(){
	document.getElementById('download_link').innerHTML = '<a href="http://www.google.com">www.google.com</a>';
}
</script>

</head>

<body onload="setTimeout('show_download();',15000);">

<div id="download_link">

</div>
</body>
</html>
Just some examples I made up..

Posted: Mon Dec 04, 2006 11:16 pm
by Maluendaster
thank man!! both scripts worked...but I have the last qustion

Is there a way to put a countdown in numbers... like 15...14...13 and the show the download link.

Posted: Mon Dec 04, 2006 11:38 pm
by Zoxive
Maluendaster wrote:thank man!! both scripts worked...but I have the last qustion

Is there a way to put a countdown in numbers... like 15...14...13 and the show the download link.
I'm happy to help out here, but we're (the community here) is not all about doing work for free. We help everyone out.

Have you tried to do it this yourself? If so post the code, and explain problems you have had.

Posted: Mon Dec 04, 2006 11:43 pm
by Maluendaster
give me a sec....

Posted: Tue Dec 05, 2006 12:05 am
by Maluendaster
i have this from another site,it should work, but it's not

Code: Select all

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function download () {
   document.getElementById('div1').style.display= 'none';
   document.getElementById('div2').style.display= '';
   return true;
}
function load () {
document.getElementById("div2").style.display = "none";
document.getElementById('div1').style.display= '';
return true;
}
//-->
</script>
<div id="div1">
<script language="Javascript">
var ts = 30; tuw1();
var loc = '';
function tuw1(){
if(ts>0){document.getElementById("div1").innerHTML = "Please wait " + ts + " seconds.";
ts = ts - 1;
setTimeout("tuw1()", 1000)} else {document.getElementById("div1").innerHTML = '<a href="#" onClick="return download();">Download file</a>';}}
</script></div>

Posted: Tue Dec 05, 2006 12:15 am
by Zoxive
Its because you need to call load(); when the pages loads.

Code: Select all

<body onload="load();">
But he is my countdown example i made..

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
// Time in Ms
var time = 10000;
// Time to subtract
var subtract = 1000;
function show_download(){
	document.getElementById('download_link').innerHTML = '<a href="http://www.google.com">www.google.com</a>';
}
function count(){
	if(time>=0){
		setTimeout('subt(subtract);',subtract);
		document.getElementById('download_link').innerHTML = time/1000 + ' seconds remaining';
	}else{
		show_download();
	}
}
function subt(remove){
	time = time-remove;
	count();
}
</script>

</head>

<body onload="count();">

<div id="download_link">
</div>

</body>
</html>