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

Problems with openWindow?? 1

Status
Not open for further replies.

baybook

MIS
Sep 16, 2004
66
US
Hello,

Hoping someone can explain this. I want to open a new window for a contact_us link. I do not want the new page to have a toolbar and I want to control the dimensons. I believe the only way to do this is with javascript.

Here is my function

<!--
Function openWindow(url){
newWindow = window.open("url", "newWin", "toolbar=no","width=300,height=450")
}
-->

Here is the body section. The window is opening in the parent window. What am I doing wrong?

<td width="25%" cellspacing="5"><div align="center" >

<a href="contact_us.htm" onclick="openWindow(contact_us.htm)" onMouseOver="MM_swapImage('blue_four','','image/four.jpg',1)" onMouseOut="MM_swapImgRestore()">

<img src="image/square4.gif" name="blue_four" width="170" height="170" border="0" id="blue_four"></a></div></td>
</tr>
 

What am I doing wrong?

Quite a few things.

JavaScript is case-sensitive. "Function" should have a lowercase "f". window.open only takes 3 parameters, not 4. Your script should be:

Code:
function openWindow(url) {
   newWindow = window.open(url, 'newWin', 'width=300,height=450');
}

Then modify your onclick to return false (to stop the new window opening) - also passing the URL as a string, not as a non-existant object / variable:

Code:
<a href="contact_us.htm" onclick="openWindow('contact_us.htm'); return(false);" onMouseOver="MM_swapImage('blue_four','','image/four.jpg',1);" onMouseOut="MM_swapImgRestore();">

Hope this helps,
Dan


The answers you get are only as good as the information you give!

 
brps...

can't you just smell it? i feel your regaining of the top spot in the JS mvp forum coming. annnnnyyy post now!

work sucks.

*cLFlaVA
----------------------------
[tt]the hand behind this pen relives a failure every day...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thank you Dan,

Please forgive this, because it is probably a sily question, BUT

You used single quotes where I have been using double quotes. Is there a difference?

return(false) - keeps the original window from chnaging to the new link. I see.

Also, you added a semicolon to the find of my swap out statement. I can see that it works both ways, but is one better than the other.

Thank you!!
 

I always use single quotes for JS and double for HTML... You can use either in JS, but single is just my preference.

Dan


The answers you get are only as good as the information you give!

 
Another note on double quotes verses single quotes...

To make things simple, I'll use an onclick command that would write something to the window status bar (does not work in FF, IE works okay. If you use FF,let me know and I can help you with something more browser friendly)

<a href="whatever site.com" onclick="window.status="blah"">click here to see blah in the window status bar!</a>

Do you see a problem so far? Onclick would think that what you are telling it to do is over because you used another double quote. Instead, we have to let it know that you want it to execute the window.status command.

<a href="whatever.com" onlick="window.status='blah'">click here to see blah in the window status bar!</a>

If you're using FF, this should be a little more friendly.

This will launch an alert box when you click the link.
<a href="whatever.com" onclick="alert('What\'s up?');">Click here for an annoying little popup</a>

This will give you the finger-as in refuse to work.
<a href="whatever.com" onlick="alert("What\'s up?");">click here for an annoying popup</a>

*semicolons are used in nearly all programming languages (javascript, PHP, perl, etc.) to end a statement. For the most part, you don't have to worry too much about them when your are using commands that don't need to go between script tags, however it's a good idea to get in the habbit of doing so.

If you're looking into studying some basic javascript to get you going, I recommend pageresource.com. The tutorials are pretty straightforward.
 

For the most part, you don't have to worry too much about them when your are using commands that don't need to go between script tags

I beg to differ. That is not the case when there is more than one command - even without the script tags... For example:

Code:
<body onload="func1(); func2();">

would become:

Code:
<body onload="func1() func2();">

No script tags, but it errors all the same.

Dan


The answers you get are only as good as the information you give!

 
Gotcha. Listen to them! I've gotten by okay, however BillyRayPreachersSon's got craploads more experience. Sorry if I misled anybody.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top