Window.open() not work in Google Chrome

Hi Friends,
I am really tired with Chrome , one of my window.open() Stuff work fine in FF and Opera in
Fedora O.S. But Chrome Did not , my code is like:

<script type="text/javascript">
	function getpage(id, type){
		$.ajax({
			type: "POST",
			data: "key="+id,
			async: false,
			url: "<?php echo site_url(); ?>/server/precp/"+type,
			success: function (msg) {
			window.open("<?php echo site_url(); ?>/server/cplogin/"+msg, "autologin");
			}
		});
}
</script>

and it call in another JavaScript function like:

function doKeyup(id,e)
	{
	   	   	
	if(e == 13) {
			var cp = $("table#serverdata tbody tr#container_tr.row_no td:nth-child(7) a#cp").html();	
			var dc = $("table#serverdata tbody tr#container_tr.row_no td:nth-child(7) a#dc").html();
			if(cp != null || dc != null ) {
				var firstId = $("table#serverdata tbody tr#container_tr.row_no td:nth-child(1) input[type=checkbox]").val();
			}
			if(cp != null) {
				alert("Enter here");
				getpage(firstId,'cp');	
				return false;
			}

and it firstly call from onkeyup as :

<input type="text" name="find_text0" id="find_text0" autocomplete="off" <?php if ('B' == $sb_pos)  { ?> onfocus="document.getElementById('find_text1').value='';" <?php } ?> onkeyup = "return doKeyup('0',event.keyCode);" />

Please Give me a Solution ASAP.

Thankfully
Anes :goof:

I see you’re using more advanced things like Ajax and Php inside your script.

Try with an easy window.open popup script first: http://www.quirksmode.org/js/popup.html

  • If this works in Chrome, it means there’s something wrong with the rest of your code, with the ajax or with your php stuff.
  • If this doesn’t work, maybe there’s a popup blocker activated in Chrome that you have to disable.

Hi,

Actually I have not tested the function, But I have experienced such problem in other browser too and finally the problem might be with your the ajax

I just did a quick test, and I can get the ajax function to work standalone just fine:


<script type="text/javascript">

	$(document).ready(function(){
		$("#target").click(function() {
			getpage("1",null);
		});
	});
	
	function getpage(id, type){
		$.ajax({
			type: "POST",
			data: "key="+id,
			async: false,
			url: "http://localhost/tmp/test.html",
			success: function (msg) {
				window.open("http://localhost/tmp/test.html", "autologin", "toolbar=no,width=500");
			}
		});
	}
</script>

I think maybe it could be failing inside of the doKeyup method… the best way to find out would be to call getpage() manually with some static values and see if that will work fine.

Another thing to try would be to do a console.log() (if you’re using firebug) or just a simple alert to see what th value of cp actually is in the doKeyup method.

If would also be worth checking that the popup blocker is not blocking it :wink:

Hi Friends,
Finally I got the solution , Actually it’s not a serious problem as we think. Simple one,

I just enable popup in Google Chrome in Preferences >> Under the Hood >> Privacy Content Settings >> Features Popups(select) >> Tick Allow all sites to allow pop up,
voila I won 50% …

In our Code , there is a small mistake(my mistake!)

function doKeyup(id,e)
	{
	   	   	
	if(e == 13) {
			var cp = $("table#serverdata tbody tr#container_tr.row_no td:nth-child(7) a#cp").html();	
			var dc = $("table#serverdata tbody tr#container_tr.row_no td:nth-child(7) a#dc").html();
			if(cp != null || dc != null ) {
				var firstId = $("table#serverdata tbody tr#container_tr.row_no td:nth-child(1) input[type=checkbox]").val();
			}
			if(cp != null) {
				alert("Enter here");
				getpage(firstId,'cp');	
				return false;
			}

Here The Value of cp and dc got in FF and opera, but in Chrome dc got null
eventhough it exist, but the value of cp is set …

it’s problem of chrome to select dc , So I simply use

var dc = $("a#dc")

and got solution. Thanks Friends for your help …

Bye Anes :lol: