473,386 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

window.open affecting parent window

Hi!

I'm using window.open to create a secondary window, and everything is
working fine with that. My problem is that as soon as that window is
opened, the parent window scrolls to the top of its page. So when the
user closes the secondary window, they've lost their place in the
parent document.

Is this normal behavior for window.open? Is there a quick way to
prevent it, or is it more likely a problem with my Javascript?

thanks!

Jul 23 '05 #1
4 5194
Lee
de*******@hotmail.com said:

Hi!

I'm using window.open to create a secondary window, and everything is
working fine with that. My problem is that as soon as that window is
opened, the parent window scrolls to the top of its page. So when the
user closes the secondary window, they've lost their place in the
parent document.

Is this normal behavior for window.open? Is there a quick way to
prevent it, or is it more likely a problem with my Javascript?


A problem with your Javascript.
You must be creating the window using something like:

<a href="#" onclick="createMyWindow()">

The # is not a comment character. It's not a place holder.
It is a link to the top of the current page.

If you don't want to follow that link, your onclick handler must return false:

onclick="createMyWindow();return false"

Jul 23 '05 #2
Lee wrote:
[...]
The # is not a comment character. It's not a place holder.
It is a link to the top of the current page.
I don't think that is strictly correct. The HTML spec says
that an anchor specified with "#" must match an ID or NAME
attribute of an element, but that the anchor may be left
empty and completed with script later.

<URL:http://www.w3.org/TR/html4/struct/links.html#edef-A>

Therefore href="#" is valid HTML but the spec does not say
what a browser should do with it. However, most browsers
seem to interpret it as being the current document and
scroll to the top.

If you don't want to follow that link, your onclick handler
must return false:

onclick="createMyWindow();return false"


The anchor (href) should point to the URL that would be
opened in the new window by JavaScript if it were enabled.
If JavaScript is diabled, the user will be taken to the anchor
and not be left with a link that (maybe) just scrolls to the
top of the page:

<a href="http://www.google.com" onclick="
createMyWindow('http://www.google.com');
return false;">Go to Google</a>

--
Rob

Jul 23 '05 #3
RobG wrote:
Lee wrote:
[...]

<--snip-->
<a href="http://www.google.com" onclick="
createMyWindow('http://www.google.com');
return false;">Go to Google</a>


<a href="http://www.google.com" target="myWindow"
onclick="createMyWindow(this.href,this.target);
return false">Go to Google in a new window</a>

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #4


You are quite right that I was using onClick to trigger a new window,
where the onClick was linked to a button in a form. The 'return
false' addition did the trick. Thanks very much! :>D

On 24 Jan 2005 18:18:39 -0800, Lee <RE**************@cox.net> wrote:
de*******@hotmail.com said:

Hi!

I'm using window.open to create a secondary window, and everything is
working fine with that. My problem is that as soon as that window is
opened, the parent window scrolls to the top of its page. So when the
user closes the secondary window, they've lost their place in the
parent document.

Is this normal behavior for window.open? Is there a quick way to
prevent it, or is it more likely a problem with my Javascript?


A problem with your Javascript.
You must be creating the window using something like:

<a href="#" onclick="createMyWindow()">

The # is not a comment character. It's not a place holder.
It is a link to the top of the current page.

If you don't want to follow that link, your onclick handler must return false:

onclick="createMyWindow();return false"


Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ben Smeets | last post by:
Hi folks, Have been trying to figure out a solution for the following problem by reading lots of threads here, but doesn't work out. Hope someone can help me. I have a parent window which...
2
by: janaka44 | last post by:
I need to open a new window, and make it work as a new session, so that i can initially load the page i need and let the user work in it without affecting the parent window's session variables
1
by: fogwolf | last post by:
First a basic outline of what I am trying to do: I want to have a page spawn a pop-up when you click "submit" on its form. On this pop-up page there will be another form. When you click "submit"...
4
by: Davey | last post by:
I have a website which has a popup window (this only opens when the user chooses to open it). In the popup window I have a <select> control which lists a selection of "classes". Each class has a...
2
by: Raj | last post by:
Hi All, I have a problem with trying to refresh the parent window from child window in order to update data in the parent window. The sequence of events are 1) I click a button in the parent...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
2
by: Robert Degen | last post by:
Hello, I got a little problem. Seems very simple: * I want to open a popup window * Popup-window uses data from its father window. BUT a parent.window does NOT point to the real parents...
2
by: epaetz | last post by:
Is there a way to decouple the linkage between a parent and a child window? Does the parent window have any sort of a collection that holds all the children that it has spawned? I want to...
3
by: rick2910 | last post by:
Hello, I have a problem with a popup. In this popup (child) are several links. I want these links to open in A NEW parent window. Code: <a href="javascript:;"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.