colderthenyou Posted January 1, 2009 Share Posted January 1, 2009 I am trying to open a new window in PHP but I need it to be centered and sized This is what I am using. ---------------------------------------------------------------------------------------------------------- { if (isset($aname)) $subnav_1 .= '<a target="_blank" class="textlink" href="forum_entry.php?id='.$id.'&page='.$page.'&category='.$category.'&order='.$order.'&descasc= '.$descasc.'">'.$lang['back_to_posting_linkname'].'</a>'; else $subnav_1 .= '<a class="textlink" href="forum_entry.php?id='.$id.'&page='.$page.'&category='.$category.'&order='.$order.'&descasc= '.$descasc.'">'.$lang['back_linkname'].'</a>'; } ---------------------------------------------------------------------------- But to get it to open in center and 500 by 500 I need to use java, Been trying for awhile now and cant get it to work. Help would be greatly appreciated!! Quote Link to comment Share on other sites More sharing options...
chronister Posted January 1, 2009 Share Posted January 1, 2009 This took all of 10 seconds on google http://www.google.com/search?q=javascript+open+new+window+centered+on+page&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a <html> <head> <script> <!-- function wopen(url, name, w, h) { // Fudge factors for window decoration space. // In my tests these work well on all platforms & browsers. w += 32; h += 96; wleft = (screen.width - w) / 2; wtop = (screen.height - h) / 2; // IE5 and other old browsers might allow a window that is // partially offscreen or wider than the screen. Fix that. // (Newer browsers fix this for us, but let's be thorough.) if (wleft < 0) { w = screen.width; wleft = 0; } if (wtop < 0) { h = screen.height; wtop = 0; } var win = window.open(url, name, 'width=' + w + ', height=' + h + ', ' + 'left=' + wleft + ', top=' + wtop + ', ' + 'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=no, resizable=no'); // Just in case width and height are ignored win.resizeTo(w, h); // Just in case left and top are ignored win.moveTo(wleft, wtop); win.focus(); } // --> </script> </head> <body> <a href="page.html" target="popup" onClick="wopen('page.html', 'popup', 300, 200); return false;"> Click here to open the page in a new window. </a> </body> </html> Nate Quote Link to comment Share on other sites More sharing options...
colderthenyou Posted January 1, 2009 Author Share Posted January 1, 2009 Yes Nate I understand , I use java in php from time to time, cant seem to make them work togeather this time. Quote Link to comment Share on other sites More sharing options...
chronister Posted January 1, 2009 Share Posted January 1, 2009 Not java, javascript. They are 2 totally separate things. And you will have to implement the code I gave into your PHP or do you already have code to open in a new window ....etc. Just using _blank as your target will not open in a window that you can manipulate as in removing address bar, status bar, buttons etc. From the code you gave, all I can see as far as the new popup window is the _blank target. Integrating the code I gave should not be too difficult for ya. Nate Quote Link to comment Share on other sites More sharing options...
colderthenyou Posted January 1, 2009 Author Share Posted January 1, 2009 target="_blank" is all I have to open the window, I need better control to keep it nice and clean centered and sizeble. yes javascript (sorry about that) Quote Link to comment Share on other sites More sharing options...
chronister Posted January 1, 2009 Share Posted January 1, 2009 Well, it would be nice if you tried it yourself. The folks here at PHPfreaks, have no problem helping those who try to help themselves, but don't like doing it for them as that does not teach anything. So just for the sake of getting this done, I have done it for you. In the future, please try to do things yourself and when you run into issues ask for help. create pop.js and add it into the head of your file. popup.js <!-- function wopen(url, name, w, h) { // Fudge factors for window decoration space. // In my tests these work well on all platforms & browsers. w += 32; h += 96; wleft = (screen.width - w) / 2; wtop = (screen.height - h) / 2; // IE5 and other old browsers might allow a window that is // partially offscreen or wider than the screen. Fix that. // (Newer browsers fix this for us, but let's be thorough.) if (wleft < 0) { w = screen.width; wleft = 0; } if (wtop < 0) { h = screen.height; wtop = 0; } var win = window.open(url, name, 'width=' + w + ', height=' + h + ', ' + 'left=' + wleft + ', top=' + wtop + ', ' + 'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=no, resizable=no'); // Just in case width and height are ignored win.resizeTo(w, h); // Just in case left and top are ignored win.moveTo(wleft, wtop); win.focus(); } // --> <?php { $href = 'forum_entry.php?id='.$id.'&page='.$page.'&category='.$category.'&order='.$order.'&descasc='.$descasc; if (isset($aname)) { $subnav_1 .= '<a href="'.$href.'" target="popup" class="textlink" onClick="wopen(\''.$href.'\', \'popup\', 300, 200); return false;">'.$lang['back_to_posting_linkname'].'</a>'; } else { $subnav_1 .= '<a href="'.$href.'" class="textlink" >'.$lang['back_linkname'].'</a>'; } } ?> I am assuming that you only wanted this to go on the first link. So try that and see what you get. You may need to adjust the size of the window. Nate Quote Link to comment Share on other sites More sharing options...
colderthenyou Posted January 1, 2009 Author Share Posted January 1, 2009 hmmm Ive been working on this for sometime I like to help myself and asking for help gives me a bit of a knot. Some I can get, and some,,well I get lost. Like this this one in lost and still lost what you have shown opens a window but with no control just as if I was using------- <a target="_blank----- still no control over the window this one got me going Quote Link to comment Share on other sites More sharing options...
chronister Posted January 1, 2009 Share Posted January 1, 2009 ??????? What do you mean no control?? If you loaded popup.js, then it gives you the ability to control the height, width, toolbars, status.... etc.. 'location=no, menubar=no, ' + 'status=no, toolbar=no, scrollbars=no, resizable=no'); I have given you what you need, you simply need to try it for yourself. It opens a new window, centered onscreen and gives you control over the size and window chrome. Don't know what else I can do for ya. Nate 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.