chauhanRohit Posted June 27, 2014 Share Posted June 27, 2014 (edited) Hi guys, I am using this code to open and close a pop up window, but as soon as i click the close button this http://localhost/popup.php?random=&button= automatically adds in the url, Please tell me what is wrong with the script <script type="text/javascript"> $(document).ready(function(){ $('a.popup-window').click(function(){ var popupBox = $(this).attr('href'); $(popupBox).fadeIn(400); var popMargTop = ($(popupBox).height() + 24)/2; var popMargLeft = ($(popupBox).width() + 24)/2; $(popupBox).css({ 'margin-top' : -popMargTop, 'margin-left' : -popMargLeft }); $('body').append('<div id="mask"></div>'); $('#mask').fadeIn(400); return false; }); $('button.close,#mask').live('click', function(){ $('#mask,.popupInfo').fadeOut(400,function(){ $('#mask').remove(); }); return false; }); }); $(document).keyup(function(e){ if(e.keyCode ==27){ $('#mask,.popupInfo, #popup-box').fadeOut(400); return false; } }); </script> </head> <body> <a href="#popup-box" class="popup-window">Click</a> <div id="popup-box" class="popupInfo"> <form> <label>ANYTHING</label></br> <input type="text" name="random"/></br> <button type="submit" name="button" class ="close">close</button> </form> </div> </body> </html> Edited June 27, 2014 by chauhanRohit Quote Link to comment https://forums.phpfreaks.com/topic/289302-unwanted-query-string-in-the-url/ Share on other sites More sharing options...
Solution cyberRobot Posted June 27, 2014 Solution Share Posted June 27, 2014 Have you tried changing the form so it uses the POST method? <form method="post"> Quote Link to comment https://forums.phpfreaks.com/topic/289302-unwanted-query-string-in-the-url/#findComment-1483274 Share on other sites More sharing options...
chauhanRohit Posted June 27, 2014 Author Share Posted June 27, 2014 Thanks that works. can u explain why this is happening ? is it by default or is it a mistake. Quote Link to comment https://forums.phpfreaks.com/topic/289302-unwanted-query-string-in-the-url/#findComment-1483277 Share on other sites More sharing options...
cyberRobot Posted June 27, 2014 Share Posted June 27, 2014 Thanks that works. can u explain why this is happening ? is it by default or is it a mistake. When a form method isn't declared, it defaults to GET which attaches the variables to the URL. Quote Link to comment https://forums.phpfreaks.com/topic/289302-unwanted-query-string-in-the-url/#findComment-1483279 Share on other sites More sharing options...
chauhanRohit Posted June 27, 2014 Author Share Posted June 27, 2014 one last thing how do i use a image instead of a button ,the code above uses a button to close the popup. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/289302-unwanted-query-string-in-the-url/#findComment-1483282 Share on other sites More sharing options...
cyberRobot Posted June 27, 2014 Share Posted June 27, 2014 how do i use a image instead of a button ,the code above uses a button to close the popup. Have you tried using an <input> tag that has the type set to "image"? Here's a quick example: http://www.echoecho.com/htmlforms14.htm Quote Link to comment https://forums.phpfreaks.com/topic/289302-unwanted-query-string-in-the-url/#findComment-1483283 Share on other sites More sharing options...
Jacques1 Posted June 27, 2014 Share Posted June 27, 2014 Sorry, but changing the method to POST makes absolutely no sense. The reason why you see parameters in the URL is because pressing the button submits the form. If you change the method, you're still submitting the form. The only difference is that now the parameters are sent via the message body rather than the URL. But they're still there. Even worse, now the browser will issue a warning whenever you try to reload the page, because it needs to know whether it should resend the data. So, no, this is not the answer. If you don't want to submit data, well, why have a form in the first place? Delete it, and the problem will go away. Quote Link to comment https://forums.phpfreaks.com/topic/289302-unwanted-query-string-in-the-url/#findComment-1483284 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.