zakk1 Posted December 23, 2008 Share Posted December 23, 2008 Hi, I need some help in creating ajax popup. I have a list of comments and I must be able to edit each comment using ajax popup but I have no idea how to create this popup. I have searched in the internet and didn't find anything. Thanks Link to comment https://forums.phpfreaks.com/topic/138251-ajax-popup/ Share on other sites More sharing options...
Philip Posted December 24, 2008 Share Posted December 24, 2008 To open the popup you could pass a variable (via GET/POST [side note: make sure if you use either of those to check to make sure the user has permissions to edit that comment, because they can be easily faked] or a server-side session) when opening the page, whether via target='_blank' for new page, or using javascript's window open method. var newWindow; function popwindow(url) { if (parseInt(navigator.appVersion)>3) { if (navigator.appName=="Netscape") { winW = window.innerWidth; winH = window.innerHeight; } if (navigator.appName.indexOf("Microsoft")!=-1) { winW = document.body.offsetWidth; winH = document.body.offsetHeight; } } var scrollbars = ",scrollbars=0,"; if(winW<(winWidth+5) || winH<(winHeight+5)) { //alert("You will have scrollbars. Your inner height and width are as following: \n"+winW+" by "+winH); scrollbars = ",scrollbars=1,"; winWidth = 800; winHeight = 600; } var data = 'height='+winHeight+',width='+winWidth+scrollbars+'location=0,status=0,directories=0,toolbar=0,menubar=0,resizable=1'; newWindow=window.open(url,'name',data); if (window.focus) {newWindow.focus()} } <a href="popup.php?id=6" onclick="popwindow('popup.php?id=6'); return false;" target="_blank">popup</a> On the popup page, have it pull data from the database - and auto populate the fields. Then use an onClick or form action to submit the form. If you know your users will have javascript enabled - using the window.open and onClick would be the fastest, and nicest way. However, being able to fall back onto the target='_blank' and form action is 100% needed if you are not sure if your users have javascript enabled. Hopefully thats what you're looking for Link to comment https://forums.phpfreaks.com/topic/138251-ajax-popup/#findComment-722917 Share on other sites More sharing options...
zakk1 Posted January 7, 2009 Author Share Posted January 7, 2009 It works. Thanks. Link to comment https://forums.phpfreaks.com/topic/138251-ajax-popup/#findComment-732000 Share on other sites More sharing options...
herghost Posted March 3, 2009 Share Posted March 3, 2009 sorry for Hi jacking this slightly, I am trying to achieve the same as this, however when I use this the new page opens as a new page, and not as a popup box? Why would this be happening? Thanks Link to comment https://forums.phpfreaks.com/topic/138251-ajax-popup/#findComment-775474 Share on other sites More sharing options...
herghost Posted March 3, 2009 Share Posted March 3, 2009 EDIT: I have noticed that this does work in internet explorer 7 but not in firefox? What would I have to change to get it to work in firefox? This is the contents of my ajax.js file: <script type="text/javascript"> <!-- //Create a boolean variable to check for a valid Internet Explorer instance. var xmlhttp = false; //Check if we are using IE. try { //If the Javascript version is greater than 5. xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { //If not, then use the older active x object. try { //If we are using Internet Explorer. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { //Else we must be using a non-IE browser. xmlhttp = false; } } //If we are using a non-IE browser, create a javascript instance of the object. if (!xmlhttp && typeof XMLHttpRequest != 'undefined') { xmlhttp = new XMLHttpRequest(); } function makerequest(serverPage, objID) { var obj = document.getElementById(objID); xmlhttp.open("GET", serverPage); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { obj.innerHTML = xmlhttp.responseText; } } xmlhttp.send(null); } var newWindow; function popwindow(url) { if (parseInt(navigator.appVersion)>3) { if (navigator.appName=="Netscape") { winW = window.innerWidth; winH = window.innerHeight; } if (navigator.appName.indexOf("Microsoft")!=-1) { winW = document.body.offsetWidth; winH = document.body.offsetHeight; } } var scrollbars = ",scrollbars=0,"; if(winW<(winWidth+5) || winH<(winHeight+5)) { //alert("You will have scrollbars. Your inner height and width are as following: \n"+winW+" by "+winH); scrollbars = ",scrollbars=1,"; winWidth = 300; winHeight = 200; } var data = 'height='+winHeight+',width='+winWidth+scrollbars+'location=0,status=0,directories=0,toolbar=0,menubar=0,resizable=1'; newWindow=window.open(url,'name',data); if (window.focus) {newWindow.focus()} } //--> </script> Link to comment https://forums.phpfreaks.com/topic/138251-ajax-popup/#findComment-775484 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.