Jump to content

Need to open a sized and centered window and what I have won't do


colderthenyou

Recommended Posts

 

 

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!!

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

 

 

 

Link to comment
Share on other sites

??????? 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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.