Solved

windows.open keeps opening new copies of named window

Posted on 2014-11-19
5
68 Views
Last Modified: 2014-11-28
Hi all,

I have some simple JavaScript that opens a webpage in a new window.

The issue is then every time the link is pressed, a new copy of the window is opened.

The following is the code I use:

window.open('MyPage.htm','UniqueWindow','scrollbars=yes');

Open in new window


Any help is greatly appreciated.

Thanks.

resourcesys
0
Comment
Question by:resourcesys
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 40453424
just make sure the target name is the same and it'll open up in the same window every time:

window.open(url, targetName);

you could also try using the _self attribute:

var myWindow = window.open("", "_self");
0
 

Author Comment

by:resourcesys
ID: 40454585
Hi Big Monty,

Normally I would agree with you but it definately is not working.

First time I've ever seen this.

Thanks for the response though.

resourcesys.
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 40455429
is the page accessible to the public?

do you have any other code running before /after the window.open command? if so try taking it out
0
 

Accepted Solution

by:
resourcesys earned 0 total points
ID: 40461600
The must be some of script interfering with is so I used the following code as a solution:

        var MyPageOpen = null;
        
        function gotoMyPageOpen()
        {            
            var theLink = 'MyPage.htm'; 
            
            try
            {
                if(MyPageOpen !== null && MyPageOpen !== false && typeof MyPageOpen !== 'undefined' && MyPageOpen !== 0 && !MyPageOpen.Closed)
                {
                    MyPageOpen.location = theLink;
                
                    MyPageOpen.focus();
                    
                    if(MyPageOpen.location == '')
                    {
                        MyPageOpen = window.open(theLink , 'MyPageOpen', 'scrollbars=yes,resizable=yes,width=1050,height=600,left=50px,top=50px');
                    }
                }
                else
                {
                    MyPageOpen = window.open(theLink , 'MyPageOpen', 'scrollbars=yes,resizable=yes,width=1050,height=600,left=50px,top=50px');
			    }
			}
			catch(e)
			{
			    MyPageOpen = window.open(theLink , 'MyPageOpen', 'scrollbars=yes,resizable=yes,width=1050,height=600,left=50px,top=50px');
			}
			finally
			{
			    var doNothing = true;
			}
        }

Open in new window


resourcesys
0
 

Author Closing Comment

by:resourcesys
ID: 40470206
No other solution provided. Own solution does work.
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question