Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript and PopUp

Status
Not open for further replies.

akrishmohan

Programmer
May 3, 2002
20
US
Hi

I have a requirement wherein I click on a link in a window which opens another window. I do not want the pop-up window blocker to be blocking this popped window.

Is there a workaround for this in JavaScript?

Thanks
Krish
 
Most versions of popup blockers will not block a window that is opened upon the clicking of a button or a link. One thing you could do is test to see if the popup opened, and if it didn't, open the page in the same window.

Something like this:

Code:
var the_win = window.open("page.html","my_win","");
if (!the_win)
    document.location = "page.html";

*cLFlaVA
----------------------------
Breaking the habit...
 
I like cLFlaVA's answer.

I offer here another perspective too....

If you look at your requirement (to show information) and not your solution (a popup window) you have many options.

First the issue of popup windows. ...

I am not aware of any trick that a browser window can do to "defeat" code built to prevent popups windoes. I assume here that you do not control the desktops that may see the popups.

Popups are blocked because they are annoying. It is usally rude to throw unwanted popups, especially those that hide under or that overwhelm the users property (his screen).

Most users configure blocking software just to block certain websites and allow others.

Then focus instead on the issue of displaying information ...

(1) REAL WINDOWS: You can ask the user to open in a new window by using a <A anchor tag with target= specified. Or .. you can ask the users to right-click and specify Open In New Window. This is the users choice.

(2) WINDOW-LIKE ELEMENTS: Layers, floating DIVs, etc act like windows but their life does not persist beyond the life of your web page.

(3) FRAMED-WINDOWS: Frames and IFRAMEs let you put entire web pages in part of your window. You can navigate your primary frame and leave the others behind to persist. You can modify the frameset's width and height to get special effects.

(4) ATTENTION-GETTING IE-ONLY APPROACHES

If your issue is to get attention after a window closes ... Yes Virginia, there is a Santa Claus (almost)

You have two tricks at your disposal to use wisely.

One is to use a modal window when you want to force attention. It's like an alert box ... but you have nice format control over it. A small amount of VB Script will do what native javascript doesnt have.

The other is to intercept a user who closes the window and insert something (like a modal window) This combined technique acts like and is as annoying as a pop-up window.


Web Page Pop-Up inside Modal Dialog Box:
Code:
<html>
<head>
</head>
<body>
<button onClick="window.showModalDialog('popup.html','', 'dialogHeight:1600px;dialogWidth:1600px;center:yes;scroll:no;status:no;help:no;unadorned:yes')">
Do Not Click Here to Close
</button>
</body>
</html>



Ordinary Modal Dialog Box:
Code:
<HTML>
<HEAD>

<SCRIPT>
function closeThisWindow()
  {
    event.returnValue = "Were you just sloppy do did you want to close the money making window?";
  }
</SCRIPT>
 
</HEAD>
 
<BODY onbeforeunload="closeThisWindow()">

<H1>I Dare You To Close this Window</H1>
 

</body>
</html>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top