Forum Moderators: open

Message Too Old, No Replies

window.open in href

         

peterinwa

4:53 pm on Feb 27, 2004 (gmt 0)

10+ Year Member



This syntax opens the new window just fine, but it replaces the current window with a white screen containing the error message [object]:

<a href='javascript:window.open("url for new window")' onMouseOver='chgImg("dietLink","greenDietgif")' onMouseout='chgImg("dietLink","blueDietgif")'>
<img src='links/Diet_blue.gif' name='dietLink'>
</a>

It should leave the current window alone except maybe for changing the link back to blue.

Thanks, Peter

peterinwa

12:27 am on Feb 28, 2004 (gmt 0)

10+ Year Member



I tried it with Netscape and got an error message which may help:

Security Error: Content at file:///C:/Websites/cph/index.html may not load data from "URL for new window".

Of course the "URL for new window" is actually an actual URL which I can't post here. Also as you can see I am working from my local C drive.

Also, as with IE, the new window did open fine. With Netscape the original screen image changed to [object Window] rather than just [object] as it did with IE.

Hope that helps, Peter

bruhaha

5:51 pm on Mar 1, 2004 (gmt 0)

10+ Year Member



The main problem with your code (from what you've listed) is that you do not name the target window in which the link is to open. I also would recommend, for browsers with javascript turned off or other "issues", that you include a standard HTML href and call the javascript with "onClick".

Something like this:

<a href="URL" target="window_name"
onClick="window.open('URL', 'window_name', ['window_options'])"
onMouseOver=...><img src=...></a>

(I've bracketed 'window_options' because they are indeed optional. But if you do wish to specify the size or location of your new window, or which toolbars, etc. you wish to appear--or not--you would add these details here. In fact, if you do not plan to specify any of these, I'm not sure what would be your reason for opening this page with javascript instead of a plain html link.)