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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controlling new windows from javascript menu links

Status
Not open for further replies.

JensenFan

Technical User
Feb 22, 2007
6
US
Forgive me. I'm a newbie, and this is probably a simple question, but so far I haven't found an answer to this. Please help! :)

I am using a javascript menu that is sort of secondary to the main menu. From this menu I am trying to have links that send the user to regular pages (in the same window), and other links that send the user pop-up windows with detialed information. Sending the user back to the regular pages on the site works well. Sending the user to new pop-up windows if proving a challenge. I want to be able to control the size and location of the new pop-up window, and well as what browser bars are shown.

The menu is a file called pop-up.js and the links are tied to words and images.

The menu programming for the links to the regular pages that work fine are like this:

document.write('<a href="index.html"><img src="picts/topics-2.jpg" vspace="3" height="75" width="100" border="1"><br>');

document.write('Home</a>');

How do I change/modify these lines to do what I want (open link in new window, control size and location of the window, and select which browser bars to show). Or do I have to take an entirely different approach? Do you need more info, let me know.

Thanks very much.
 
Thanks. I tried that, and the menu disappeared from the webpage (i.e., it didn't work). I might have done something wrong (strong possibility), so let me try again, using the info page you suggested as a guide.
 
What I had tried was:

document.write('<a href="javascript:void(0)"onclick="window.open('index.html','welcome','width=300,height=200, screenX=10,screenY=250,top=10,left=250, menubar=no,status=yes,
location=no,toolbar=no,scrollbars=no')"><img src="picts/topics-team.jpg" vspace="3" height="75" width="100" border="1"><br>');
document.write('Home</a>');

I'm sure I broke at least a couple rules there...
 
Can you post the popup.js file? I'm not quite understanding what is going on here.

Or could you possibly post the url where you are working on this site(if it's not on an intranet)?

[small]"I see pretty girls everywhere I look, everywhere I look, everywhere I look. - Band song on movie "The Ringer"[/small]
<.
 
Here's the entire file:

<!-- Begin

// NOTE: If you use a ' add a slash before it like this \'

// NOTE: search for the text you want to edit use: edit - find


document.write('<TABLE cellpadding="5" cellspacing="0" border="0" width="125"><tr><td align="center">');
document.write('<span class="subtitle">');

document.write('<BR>');

document.write('Quick Links<BR>');

document.write('</span>');

document.write('');

document.write('<span class="subtitle">');

document.write('<BR>');

document.write('</span>');

document.write('<br>');

document.write('<a href="index.html"><img src="picts/topics-2.jpg" vspace="3" height="75" width="100" border="1"><br>');

document.write('Home</a>');

document.write('<br><br>');

document.write('<IMG SRC="picts/spacer.gif" HEIGHT="5" WIDTH="100" border="0" alt="image"><BR>');

document.write('</td></tr></table>');

// End -->
 
DUH, here is the problem:
You have to escape your quotes inside the quotes.

Code:
document.write('<a href="javascript:void(0)"onclick="window.open(\"index.html\",\"welcome\",\"width=300,height=200, screenX=10,screenY=250,top=10,left=250, menubar=no,status=yes,
location=no,toolbar=no,scrollbars=no\")"><img src="picts/topics-team.jpg" vspace="3" height="75" width="100" border="1"><br>');
document.write('Home</a>');

That should work.

[small]"I see pretty girls everywhere I look, everywhere I look, everywhere I look. - Band song on movie "The Ringer"[/small]
<.
 
I figured it would be something like that.

However, I tried it, and the menu no longer shows up on the webpage. Something doesn't like something.

Here is the webpage: It's the menu on the right. (old version that works is up).
 
I'm sorry I'll test it out myself and find out what's going on.

[small]"I see pretty girls everywhere I look, everywhere I look, everywhere I look. - Band song on movie "The Ringer"[/small]
<.
 
For some reason, I couldn't get the window.open to work when putting it inline on the onclick handler, but for the anchor to call a function, it works fine:
Code:
document.write('<TABLE cellpadding="5" cellspacing="0" border="0" width="125"><tr><td align="center">');
document.write('<span class="subtitle">');

document.write('<BR>');

document.write('Quick Links<BR>');

document.write('</span>');

document.write('');

document.write('<span class="subtitle">');

document.write('<BR>');

document.write('</span>');

document.write('<br>');

document.write('<a href="javascript:openWindow()"><img src="picts/topics-2.jpg" vspace="3" height="75" width="100" border="1"><br>');

document.write('Home</a>');

document.write('<br><br>');

document.write('<IMG SRC="picts/spacer.gif" HEIGHT="5" WIDTH="100" border="0" alt="image"><BR>');

document.write('</td></tr></table>');

function openWindow() {
   window.open("[URL unfurl="true"]http://www.google.com","hello","resizable=1,toolbar=no,minimize=no,status=no,memubar=no,location=no,scrollbars=no,top=200,left=200");[/URL]
}

All you have to do it put your window.open statement in in place of mine.

This should all be done in your .js file.

I did test this and it works, sorry about the hassle.



[small]"I see pretty girls everywhere I look, everywhere I look, everywhere I look. - Band song on movie "The Ringer"[/small]
<.
 
Thanks. That works perfectly.

No need to be sorry about any hassle. There was none. You were a huge help. Much appreciated.
 
Glad I could eventually help.

The hassle was that I should have been on that a lot faster than I was.

[small]"I see pretty girls everywhere I look, everywhere I look, everywhere I look. - Band song on movie "The Ringer"[/small]
<.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top