Jude Posted January 9, 2007 Share Posted January 9, 2007 Please help,Im a newbie and all i can find is complex code for the wrong thing i am looking for. All i need is a simple dialog box, i have a website whereby when the user clicks the link i want a dialog box to pop up asking the user whether they want to open, save or cancel the operation.Although this may seem simple i have no idea where to start ive hit a mental block, as this isn't my usual programming code.Please help its much appreciatedMany thanks Quote Link to comment Share on other sites More sharing options...
Cep Posted January 9, 2007 Share Posted January 9, 2007 I asked for this not long ago, you could try searching for a post about downloading an XML file. Its basically to do with using the header function.[code=php:0] header('Content-type: text/xml'); // It will be called downloaded.xml header('Content-Disposition: attachment; filename="MyFilname.xml"');[/code] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 9, 2007 Share Posted January 9, 2007 [b]Cep[/b]: Your answer has nothing to do with the question.As to the answer to the OP's question, this is best done with Javascript, not PHP.Ken Quote Link to comment Share on other sites More sharing options...
Cep Posted January 9, 2007 Share Posted January 9, 2007 It has everything to do with it,All she needs is a standard button that posts back to the PHP, and in there she can run the above (albiet she will need to change the content-type) and that will bring up a dialog box to open, save or cancel.If you don't believe me here's an example,On the opening form,[code=php:0]<?phpif (isset($_POST['action'])) { // Content type of file you want them to download header('Content-type: text/xml'); // It will be called default.xml header('Content-Disposition: attachment; filename="default.xml"'); // readfile("default.xml"); exit;} else { $html = "<html> <head> <title>form</title> </head> <body> <form name='myform' method='post' action='script.php'> <input name='action' type='hidden' value='download' /> <input name='mybutton' type='submit' value='Download' /> </form> </body> </html>"; echo $html;}?>[/code]Just wack a mock up default.xml file alongside the script and test it for yourself. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 9, 2007 Share Posted January 9, 2007 Cep : No need to reinvent the wheel, it's best done with javascript! Quote Link to comment Share on other sites More sharing options...
Cep Posted January 9, 2007 Share Posted January 9, 2007 I know but I just wanted to prove it can be done :DBesides what if the client has javascript disabled? This method will still work. Quote Link to comment Share on other sites More sharing options...
Jude Posted January 10, 2007 Author Share Posted January 10, 2007 Hey guys thanks for you're help, im sure it can be done in both programming languauges, i just need the easiest i suppose as they aren't my main programming languages. Is it easier done in javascript??If so i dont suppose either of you guys know how to do this in javascript??Thank you so much :) Quote Link to comment Share on other sites More sharing options...
JustinK101 Posted January 10, 2007 Share Posted January 10, 2007 Put this in the header in between <head> and before </head>.[code]<script type="text/javascript">//FUNCTION WRITTEN BY JUSTINK101function new_window(w, h, url, name) { function centerWindow(myWidth, myHeight) { leftPos = 0 topPos = 0 if (screen) { leftPos = (screen.width / 2) - (myWidth / 2); topPos = (screen.height / 2) - (myHeight / 2); } } function makeNewWindow(url, name, width, height, cenLeft, cenTop) { parentWindow = window.open(url, name, 'width=' + width + ',height=' + height + ',toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=false, left=' + cenLeft + ', top=' + cenTop +'') } centerWindow(w, h); makeNewWindow(url, name, w, h, leftPos, topPos);}</script>[/code]<a href="javascript:" onclick="new_window(200, 200, 'mynewpage.php', 'myWindow');">Then simply write your PHP in that new file mynewpage.php. SHould get you started. By the way, enjoy my little niffty js function, quite nice, I use it all the time. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.