Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pop-up Windows

Status
Not open for further replies.

cactus1000

Programmer
Aug 31, 2001
149
US
I've posted this to the JavaScript forum, but maybe someone here can help.

This is a problem that only occurs in Netscape (I'm using 4.7)

This function creates a pop-up window. If I close the window before opening another everything is fine. However, If I don't close the window, and I click on another link, new content gets loaded to the window, but it loses focus, and goes behind my main window. This doesn't happen in IE.

It also overwrites the first window instead of creating an additional window as it does in IE.

Here's the code:

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
function makeNewWindow(professorsFolder) {
var newWindow

if (!newWindow || newWindow.closed) {
newWindow = window.open(&quot; + professorsFolder + &quot;/index2.html&quot;,&quot;&quot;,&quot;status,height=400,width=635&quot;)

if (!newWindow.opener) {
newWindow.opener = window
}

newWindow.moveTo(125,50)
newWindow.document.close() // close layout stream
} else { // window's already open, bring to front
newWindow.focus()
}
}
</script>
 
Ok, are you only dealing with one window now? As in, your function creates a new window, and if a user clicks on a link on the parent page, it opens the links contents to the already open window? You don't want to open multiple windows?

If your loading new material to the same existing window, this is what I did to to get it to &quot;re-focus&quot; on the popup. Add onLoad=&quot;javascript:window.focus();&quot; to your body tag of the page you are loading into the popup window. Then, once the page is loaded into the popup (in the background), it 'pops' to the fore.

Is that what you were looking for?
 
Thanks for your response!

Actually, I solved half the problem by putting an additional &quot;newWindow.focus()&quot; right after the code that opens the window.

if (!newWindow || newWindow.closed) {
newWindow = window.open(&quot; + professorsFolder + &quot;/index2.html&quot;,&quot;professorsFolder&quot;,&quot;status,height=400,width=635&quot;)
newWindow.focus()


I'm not sure why Netscape requires this, but whatever...

But I'm still puzzled as to why Netscape opens the links contents to the already open window, while IE creates an additional window. I'd like an additional window to be created so that users can go back to the first pop-up window (which would now be minimized).

Any thoughts?
 
As long as you are naming the new window you are creating, (all the same) IE should load any new content to the same window.

For example:
Code:
function openwindowlink(url) {
newwin = window.open(url,&quot;products&quot;,&quot;height=505,width=780,toolbar=no,menubar=no,location=no,scrollbars=0,resizable=no,status=no,border=yes, screenx=5, screeny=5, left=5, top=5&quot;)
}
I use this function to load a popup that displays a detailed description of a product. In that product description page, I have the following bit in the header:
Code:
onload=&quot;JavaScript: window.focus()&quot;
That helps to bring the page to the front when in is loaded.

Additonaly, just to make sure, I redeclair the window name in the new file:
Code:
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
var documentName = &quot;products&quot;;
</script>
But that gets involved with a bunch of other stuff, so I don't know if its relevant.

Now, if I understand you corectly, you want to have two popups? The first one pops up, and stays, while all new popups open into another window, without creating an ungodly mess?

In that case, you could try passing the document's name in your link, a unique name for the first popup, then identical names for each consecutive popup.
Code:
function openwindowlink(url, docName) {
newwin = window.open(url,docName,&quot;height=505,width=780,toolbar=no,menubar=no,location=no,scrollbars=0,resizable=no,status=no,border=yes, screenx=5, screeny=5, left=5, top=5&quot;)
}

Is this any closer to what you were looking for?
 
Well, I tried to pass a unique name for each window like this:

Here's the link:

<a href=&quot;javascript:void(0)&quot; onClick=&quot;makeNewWindow('aaron')&quot;>Benjamin Aaron</font>

And here's what I put in the function:


function makeNewWindow(professorsFolder) {
var newWindow

if (!newWindow || newWindow.closed) {
newWindow = window.open(&quot; + professorsFolder + &quot;/index2.html&quot;,&quot;professorsFolder&quot;,&quot;status,height=400,width=635&quot;)

I thought it would treat &quot;professorsFolder&quot; as a variable, (like it does when inserted into the URL)thus giving a unique name to each new window, but instead it seemed to treat this as a constant.

If I could find a way to pass each person's name to the window name, I think that would do what I want.

I agree that endless pop-up windows are going to be a mess, but as of now, that's what the boss wants.

Thanks for all of your help!
 
You don't nedd the quotes :

function makeNewWindow(professorsFolder) {
var newWindow

if (!newWindow || newWindow.closed) {
newWindow = window.open(&quot; + professorsFolder + &quot;/index2.html&quot;,&quot;professorsFolder&quot;,&quot;status,height=400,width=635&quot;)


without quotes


function makeNewWindow(professorsFolder) {
var newWindow

if (!newWindow || newWindow.closed) {
newWindow = window.open(&quot; + professorsFolder + &quot;/index2.html&quot;,professorsFolder,&quot;status,height=400,width=635&quot;)
Regards

Big Dave

davidbyng@hotmail.com


** If I am wrong I am sorry, but i'm only trying to help!! **
 
Well, you could do this in your function:
Code:
function makeNewWindow(professorsFolder, profsName) {
    var newWindow

    if (!newWindow || newWindow.closed) {
        newWindow = window.open(&quot;[URL unfurl="true"]http://www.law.ucla.edu/faculty/bios/&quot;;[/URL] + professorsFolder + &quot;/index2.html&quot;,profsName,&quot;status,height=400,width=635&quot;)
Then in your link:
Code:
<a href=&quot;javascript:void(0)&quot; onClick=&quot;makeNewWindow('aaron','benaron')&quot;>Benjamin Aaron

Does the light of clarity shine through the clouds, or did I just throw more mud?
 
Yeah - it was the quote marks! (can you tell I don't know what I'm doing?)

Thanks to you both!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top