December 24, 200916 yr Hey guys, quick Q. Creating a small script for downloading, just for experience, and i have this code right now: <title>Download</title> <body> Download Example.rar by clicking the download button.<br /> <input type="button" OnClick="location.href='Example.rar'";" else OnClick="location.href='temp.txt'";" value="Download"> I was wondering if you could combine the OnClick's and create 2 scripts? So, onClick="location.href='google.com';" and then run onClick="location.href='Example.rar';" I've seen this done before on other site, just wondered if it was as simple as on onClick, and how to do it? Regards, EDIT :: Forgot to add, Where onClick="location.href='google.com';", i wanted that was a popup. Forgot to add that in xD
December 25, 200916 yr Assign to onclick some twoClickFunction(). This function, being activated through click, will check some variable, say, Flag (by default Flag=0;). If Flag=0, {1st action is executing and Flal=0}; else {2nd action; Flag=1;}. Simple switch. Something like that.
December 25, 200916 yr Author Sorry mate, im abit useless and i dont understand :S Could you explain it abit simpler please? Regards,
December 26, 200916 yr As for me 'abit simplier' means to write code, properly speaking: <script language="JavaScript"> Flag = 0; function popup() { window.open ("http://google.com","mywindow","menubar=1,resizable=1,width=350,height=250"); } function twoClixFunction() { var d = new Date(); var time = d.getHours(); if (Flag == 0) { popup(); Flag=1; f.butt.value = 'Click Me for new location'; } else { location.href='http://yahoo.com'; Flag=0; f.butt.value = 'Click me for popup'; } } </script> <form name="f"> <input type="Button" name="butt" onclick="twoClixFunction()" value="Click me for popup" /> </form>
December 30, 200916 yr Author Thanks, works to some degree. Was hoping that the user would have to click twice, so literally speaking = Page > Clicks button > Popup > then file for download. Instead of Page > clicks button > popup > clicks button > file download... If that makes sense?
December 30, 200916 yr Do I correctly understand that you want to assign two consecutive events to the single click? If yes, it is very easy. <script language="Javascript"> function popup() { window.open ("http://google.com","mywindow","menubar=1,resizable=1,width=350,height=250"); } function loadfile() { location.href='http://www.webdesignerforum.co.uk/uploads/av-16198.jpg'; } </script> <form name="f"> <input type="Button" name="butt" onclick="popup(); loadfile()" value="Click me for popup AND load file" /> </form>
Create an account or sign in to comment