Sunday, May 19, 2024
177
rated 0 times [  183] [ 6]  / answers: 1 / hits: 25114  / 15 Years ago, sat, june 13, 2009, 12:00:00

i have Problem with opening popups in javascript i have this function to open my popups in IE6 and IE7:



function open_window(Location,w,h) //opens new window
{
var win = width=+w+,height=+h+,menubar=no,location=no,resizable,scrollbars,top=500,left=500;
alert(win) ;
window.open(Location,'newWin',win).focus();

}


it's working . i mean my new window opens but an error occurs. The Error Message is :




'window.open(...)' is null is not an object.

do you want to countinue running script on this page ?




then i have button in onclick event it's will call a function to close current window an refresh the opener function is



function refreshParent(location) 
{
window.opener.location.href = location ;
window.close();
}


it's also gives me error : window.opener.location is null or not an object but i'm sure i'm passing correct parameters



i call it like this :



for second part :



<input type=button name=pay value=test onclick=refreshParent('index.php?module=payment&task=default') >


for first part :



<a onclick=javascript:open_window('?module=cart&task=add&id=<?=$res[xproductid]?>&popup=on','500' , '500')  style=cursor:pointer id=addtocard> <img src=../images/new_theme/buy_book.gif width=123 border=0/> </a>


it's really confuse me . Please Help ;)


More From » internet-explorer

 Answers
15

When popup windows opened using window.open are blocked by a popup blocker, a feature of pretty much any modern browser these days, the return value of window.open() is not a window object, but null.



In order to circumvent these issues you would need to test the value returned by window.open() before attempting to invoke any methods on it.



Below is a piece of code to demonstrate how to go around this problem:



function open_window(Location,w,h) //opens new window
{
var options = width= + w + ,height= + h;
options += ,menubar=no,location=no,resizable,scrollbars,top=500,left=500;

var newwin = window.open(Location,'newWin',options);

if (newwin == null)
{
// The popup got blocked, notify the user
return false;
}

newwin.focus();
}


In general, popup windows should be used only as a last resort or in controlled environments (internal company website, etc). Popup blockers tend to behave in very inconsistent ways and there may be more than a single popup blocker installed in a given browser so instructing the user on how to allow popups for a given website is not necessarily a solution. Example: IE7 + Google toolbar = two popup blockers.



If I may suggest, perhaps you should consider using something like this:
http://jqueryui.com/demos/dialog/



The advantages are numerous:




  1. Skinnable, so you can create a more consistent look to match your website.

  2. No popup blockers.

  3. Good API and documentation that is consistent across most, if not all, major browsers.



If you still require that the newly opened window contain an external URL, you could use an IFRAME inside the opened dialog window.



Hope this helps,



Lior.


[#99322] Tuesday, June 9, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ayleen

Total Points: 447
Total Questions: 88
Total Answers: 109

Location: Belize
Member since Mon, Jun 20, 2022
2 Years ago
ayleen questions
Thu, May 12, 22, 00:00, 2 Years ago
Sat, Mar 6, 21, 00:00, 3 Years ago
Tue, May 26, 20, 00:00, 4 Years ago
Sat, Apr 11, 20, 00:00, 4 Years ago
;