Jump to content

AJAX popup


zakk1

Recommended Posts

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

  • 2 weeks later...
  • 1 month later...

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.