Same button to download and open a different URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Same button to download and open a different URL

Post 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.
Corvin
Forum Commoner
Posts: 49
Joined: Sun Dec 03, 2006 1:04 pm

Post by Corvin »

You have to use JavaScript for that. Check the JS-Code of a website where this functionality is used.
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Post by Maluendaster »

do you know where i can find a site using that???
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Re: Same button to download and open a different URL

Post 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
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post 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..
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Post 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.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post 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.
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Post by Maluendaster »

give me a sec....
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Post 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>
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post 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>
Post Reply