473,583 Members | 3,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IE javascript window.open problem

Hello,

I am using the following javascript code to open a new window.
Somehow, IE always opens a new window. It doesn't open target url in
the window name given.

All i want is, if there is a window "MyWin" already open, then the
main window should load the target url in "MyWin" and not open a new
window again.

<!-- Code Starts -->
<html><head></head>
<Script Language="javas cript">
function Callme()
{
var win2 = window.open("Te st2.htm", "MyWin");
}

/* I don't want to use following type of code as it serves the purpose
initially but not if you refresh the main page.*/
/*
function Callme(location ){
var win2;
if (typeof win2 == "object") {
win2.location.r eplace(location );
}
else{
win2=window.ope n(location,"MyW in",null,true );
}
}
// thanks
*/

</Script>
<body>
<form>
<input type="button" value="Click Me" onClick="Callme ();">
</form>
</body>
</html>
<!-- Code Ends -->

Any hint/help apprreciated.
IE version : 6.0.2800.1106.x psp2.030422-1633
OS : Windows XP

Thanks,
Samir
Jul 23 '05 #1
2 3496
Samir Pandey wrote:
Hello,

I am using the following javascript code to open a new window.
Somehow, IE always opens a new window. It doesn't open target url in
the window name given.

All i want is, if there is a window "MyWin" already open, then the
main window should load the target url in "MyWin" and not open a new
window again.

<!-- Code Starts -->
<html><head></head>
<Script Language="javas cript">
<script> tags should appear either inside <head>...</head> or inside
<body>...</body>.

The "language" attribute is deprecated. Use type="text/javascript"
instead.
function Callme()
{
var win2 = window.open("Te st2.htm", "MyWin");
}

/* I don't want to use following type of code as it serves the purpose
initially but not if you refresh the main page.*/
/*
function Callme(location ){
var win2;
if (typeof win2 == "object") {


Because you are declaring win2 on every call to the function, it will
_never_ be typeof "object". If you want to do something like this, use a
global variable to track the existance of win2. This task is covered in
the FAQ:

<url: http://jibbering.com/faq/#FAQ4_10 />

--
| Grant Wagner <gw*****@agrico reunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #2
Samir Pandey wrote:
I am using the following javascript code to open a new window.
Somehow, IE always opens a new window. It doesn't open target url in
the window name given.

All i want is, if there is a window "MyWin" already open, then the
main window should load the target url in "MyWin" and not open a new
window again.

<!-- Code Starts -->
<html><head></head>
In Valid (X)HTML, the "head" element must not be empty. It must at
least contain a "title" element. Besides, have you used a proper
DOCTYPE declaration? If not, that would make the document invalid,
too. You cannot build a house on a swamp.
<Script Language="javas cript">
<script type="text/javascript">
function Callme()
{
var win2 = window.open("Te st2.htm", "MyWin");
}

/* I don't want to use following type of code as it serves the purpose
initially but not if you refresh the main page.*/
/*
function Callme(location ){
var win2;
if (typeof win2 == "object") {
Since win2 is declared local (note the `var' keyword), this branch will
be never executed as `win2''s value and type is always `undefined'.
win2.location.r eplace(location );
}
else{
win2=window.ope n(location,"MyW in",null,true );
You maybe run into a scope problem here. `location' is already a
property of the window object. Use another variable identifier.

window.open has only three arguments: The URI of the resource to
access, the internal name of the new Window object, and a *string*
containing definitions of its features. I wonder what you think
`null' and `true' will do.

And there is no need to check if the window is already open if you use
a unique internal window name. If it is not open, it will be opened,
if it is still open, it will be reused. All you may want to do is to
focus the window so it does not remain in the background if it is reused.
}
}
function isMethodType(s)
{
return (s == "function" || s == "object");
}

function callMe(sURI)
{
var result = window.open(sUR I, "MyWin", "");

if (result && isMethodType(ty peof result.focus))
{
result.focus();
}

return result;
}

var win2;
// ...
win2 = callMe("a_fool" );
// thanks
?
*/
As you comment everything out, ...
</Script>
</script>
<body>
<form>
<input type="button" value="Click Me" onClick="Callme ();">
.... why do you expect this to work anyway?
[...]
IE version : 6.0.2800.1106.x psp2.030422-1633
OS : Windows XP


Ohh, would just anyone post this precise information in the first place!
PointedEars
Jul 23 '05 #3

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

Similar topics

13
9422
by: Kai Grossjohann | last post by:
It seems that Ctrl-N in Mozilla opens a new empty browser window. That's fine, I don't need to do anything about it. But Ctrl-N in IE appears to clone the current window. Is there a way to intercept the key so that I can do stuff on the server side to make the new window behave correctly? (We have a JSP-based webapp which stores state in...
0
7894
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...
0
7824
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8321
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...
1
7931
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...
0
8191
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...
0
6578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3816
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2331
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
0
1154
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...

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.