SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2006
    Location
    Dubrovnik, Croatia
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Popup window blur

    Hi!

    I'm heaving problems with popup window blur, basically i want popup window to stay under main window for my users.
    I have regular popup script that opens window

    Code JavaScript:
    function writeConsole(content) {
     
     	var wobj = window.open('','test',
     
    	'width=250,height=250'
     
    	+',menubar=no'
     
    	+',toolbar=no'
     
    	+',status=no'
     
    	+',scrollbars=no'
     
    	+',resizable=no'
     
    	+',location=no'
     
    	+',left=20'
     
    	+',top=450');
     
     
    	if (wobj != null)
     
    	{
     
    	  wobj.document.writeln(
     
    	   '<html><head><title>sex.it</title><style>* {padding:0; margin: 0;}</style><script type="text/javascript">setTimeout("window.opener.focus()", 2250);window.onload = function(){ window.opener.focus(); }</script></head>'
     
    	    +'<body bgcolor=white>'
     
    	    + content
     
    	    +'</body></html>'
     
    	  )
     
     
     
     
     
    	}
     
    }

    I'm calling this function when page loads.
    Now this is working when timeout is rather hight 2250 if i lower it to lets say 50 than it's not working. I guess it has to wait for browser to finish loading stuff. This code works for IE, FF3 but on Chrome and Firefox 4 i can't get this thing running. And i have seen sites, porn doing this on all browsers but i can't extract the code can someone help pls

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    The following might help in regard to pop-under windows.
    http://www.codeave.com/javascript/code.asp?u_log=7068
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2006
    Location
    Dubrovnik, Croatia
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understand behaviour but that's not working. Well it's working on IE and FF3 but on FF4 and chrome that's not working i simply can't tell window to go under main window.

  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2006
    Location
    Dubrovnik, Croatia
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And also that example from your link is not working ...

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by djomla View Post
    And also that example from your link is not working ...
    If it' working on some web browsers and others, quite possibly the web browser itself does not allow that behaviour to occur.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2006
    Location
    Dubrovnik, Croatia
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the script that does the job!


    Code JavaScript:
    $.popunder = function(content, title) {
     
                var _parent = self;
     
                var bPopunder = !($.browser.mozilla && $.browser.version >= '2.0');
     
     
     
                if (top != self) {
     
                    try {
     
                        if (top.document.location.toString()) {
     
                            _parent = top;
     
                        }
     
                    }
     
                    catch(err) { }
     
                }
     
     
     
                /* create popunder dummy*/
     
                var popunder = _parent.window.open('about:blank', '', 'toolbar=0, scrollbars=1, location=1, statusbar=1, menubar=0, resizable=1, height = 100, width= 100');
     
    	    popunder.document.writeln('<html><head><title>' + title +'</title><style>* {padding:0; margin: 0;}</style></head><body bgcolor=white>' + content   +'</body></html>'
     
    	    );
     
                if (popunder) {
     
                    popunder.blur();
     
                    if (bPopunder) {
     
                        /* classic popunder, should work on webkit*/
     
                        _parent.window.blur();
     
                        _parent.window.focus();
     
                        try { opener.window.focus(); }
     
                        catch (err) { }
     
                    }
     
                    else {
     
                        /* popunder for e.g. ff4 */
     
                        popunder.init = function(e) {
     
                            with (e) {
     
                                (function() {
     
                                    if (typeof window.mozPaintCount != 'undefined') {
     
                                        var x = window.open('about:blank');
     
                                        x.close();
     
                                    }
     
     
     
                                    try { opener.window.focus(); }
     
                                    catch (err) { }
     
                                })();
     
                            }
     
                        };
     
                        popunder.init(popunder);
     
                    }
     
                }
     
     
     
                return this;
     
            }

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,716
    Mentioned
    103 Post(s)
    Tagged
    4 Thread(s)
    With Google Chrome no popunder occurs. Instead the web browser says that the popup has been blocked. My Firefox says that it blocked it too.

    Internet Explorer loaded the popunder page, but the script on Internet Explorer then set my Google Chrome window to the page that's visible. That's impressive.

    How about Safari - nope. It says that it blocked things too.
    I don't have Opera installed on here, but I doubt things will improve there too.

    Dare I say it, but I don't think that the script is ready for prime-time yet.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #8
    SitePoint Enthusiast
    Join Date
    Dec 2006
    Location
    Dubrovnik, Croatia
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure it's blocked, every popup is by default blocked on chrome and firefox (that much i can say 100%) when you allow it (like every normal popup window in the world - you should know this stuff) it does the job. Maybe it's not ready completely but it does the job and it's a good start for everyone else, much better than your first advice.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •