473,778 Members | 1,911 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5213
Lee
de*******@hotma il.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="create MyWindow()">

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="create MyWindow();retu rn 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="create MyWindow();retu rn 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="myWindo w"
onclick="create MyWindow(this.h ref,this.target );
return false">Go to Google in a new window</a>

--
Randy
comp.lang.javas cript 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*******@hotm ail.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="create MyWindow()">

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="create MyWindow();retu rn false"


Jul 23 '05 #5

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

Similar topics

1
27590
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 opens a popup window (child). What i would like to do, is to be abke to keep surfing to other pages in the parent and after (lets say) a couple of new pages, still be able to say "child.setFocus()";
2
1373
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
16034
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" on the pop-up's form I want the pop-up to close & a new page to load in the "parent" window/page. I have this working in IE but cannot get it to work in Firefox. The parent window correctly loads the new page after submitting from the pop-up,...
4
22212
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 description and a class_id (stored in the value attribute of each option). The user will then select a class from the drop-down list. What I want to do is have a control in the parent browser window which can store the class_id and the...
2
23511
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 window to open a child window thru javascript window.open 2) I have some functionality in the child window that changes the data
1
11583
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 http://weblogs.asp.net/asmith/archive/2003/09/15/27684.aspx but it was far more complex then I needed. (I got lost trying to figure it all out). Therefore, here goes my simple "web dialog box with parent event handler fireing" solution. ...
2
19244
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 window. Alerting parent.window.location.href shows me, I'm at the wrong window location.
2
2760
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 break that connection from the parent side or the child side, it doesn't matter as long as the communication link is completely broken. I don't want the parent to be aware of the child and vice-versa.
3
3493
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:;" onclick="opener.location.href='http://www.test.com/'">Link name</a>
0
9629
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10127
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5500
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4033
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2865
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.