Rectangle 27 23

I put the following javascript in the page header and it seems to work. It detects when the browser does not support showModalDialog and attaches a custom method that uses window.open, parses the dialog specs (height, width, scroll, etc.), centers on opener and sets focus back to the window (if focus is lost). Also, it uses the URL as the window name so that a new window is not opened each time. If you are passing window args to the modal you will need to write some additional code to fix that. The popup is not modal but at least you don't have to change a lot of code. Might need some work for your circumstances.

<script type="text/javascript">
  // fix for deprecated method in Chrome 37
  if (!window.showModalDialog) {
     window.showModalDialog = function (arg1, arg2, arg3) {

        var w;
        var h;
        var resizable = "no";
        var scroll = "no";
        var status = "no";

        // get the modal specs
        var mdattrs = arg3.split(";");
        for (i = 0; i < mdattrs.length; i++) {
           var mdattr = mdattrs[i].split(":");

           var n = mdattr[0];
           var v = mdattr[1];
           if (n) { n = n.trim().toLowerCase(); }
           if (v) { v = v.trim().toLowerCase(); }

           if (n == "dialogheight") {
              h = v.replace("px", "");
           } else if (n == "dialogwidth") {
              w = v.replace("px", "");
           } else if (n == "resizable") {
              resizable = v;
           } else if (n == "scroll") {
              scroll = v;
           } else if (n == "status") {
              status = v;
           }
        }

        var left = window.screenX + (window.outerWidth / 2) - (w / 2);
        var top = window.screenY + (window.outerHeight / 2) - (h / 2);
        var targetWin = window.open(arg1, arg1, 'toolbar=no, location=no, directories=no, status=' + status + ', menubar=no, scrollbars=' + scroll + ', resizable=' + resizable + ', copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
        targetWin.focus();
     };
  }
</script>

It seems IE has same problems too. If we override the function by removing the first if, it works in all 3 major browsers.

Any sample in jsfiddle ? jsfiddle.net/grj4x5k9 sample using HTML5 dialog (with this problems)

javascript - How can I make window.showmodaldialog work in chrome 37? ...

javascript jquery asp.net google-chrome cross-browser
Rectangle 27 22

I put the following javascript in the page header and it seems to work. It detects when the browser does not support showModalDialog and attaches a custom method that uses window.open, parses the dialog specs (height, width, scroll, etc.), centers on opener and sets focus back to the window (if focus is lost). Also, it uses the URL as the window name so that a new window is not opened each time. If you are passing window args to the modal you will need to write some additional code to fix that. The popup is not modal but at least you don't have to change a lot of code. Might need some work for your circumstances.

<script type="text/javascript">
  // fix for deprecated method in Chrome 37
  if (!window.showModalDialog) {
     window.showModalDialog = function (arg1, arg2, arg3) {

        var w;
        var h;
        var resizable = "no";
        var scroll = "no";
        var status = "no";

        // get the modal specs
        var mdattrs = arg3.split(";");
        for (i = 0; i < mdattrs.length; i++) {
           var mdattr = mdattrs[i].split(":");

           var n = mdattr[0];
           var v = mdattr[1];
           if (n) { n = n.trim().toLowerCase(); }
           if (v) { v = v.trim().toLowerCase(); }

           if (n == "dialogheight") {
              h = v.replace("px", "");
           } else if (n == "dialogwidth") {
              w = v.replace("px", "");
           } else if (n == "resizable") {
              resizable = v;
           } else if (n == "scroll") {
              scroll = v;
           } else if (n == "status") {
              status = v;
           }
        }

        var left = window.screenX + (window.outerWidth / 2) - (w / 2);
        var top = window.screenY + (window.outerHeight / 2) - (h / 2);
        var targetWin = window.open(arg1, arg1, 'toolbar=no, location=no, directories=no, status=' + status + ', menubar=no, scrollbars=' + scroll + ', resizable=' + resizable + ', copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
        targetWin.focus();
     };
  }
</script>

It seems IE has same problems too. If we override the function by removing the first if, it works in all 3 major browsers.

Any sample in jsfiddle ? jsfiddle.net/grj4x5k9 sample using HTML5 dialog (with this problems)

javascript - How can I make window.showmodaldialog work in chrome 37? ...

javascript jquery asp.net google-chrome cross-browser
Rectangle 27 0

Yes, handle the onbeforeUnload event for the popup window and then call a function on the parent window using:

window.opener.myFunction()

jquery - is it possible to open a popup with javascript and then detec...

javascript jquery popup
Rectangle 27 0

Try looking into the unload and beforeunload window events. Monitoring these should give you an opportunity to call back when the DOM unloads when the window is closed via something like this:

var newWin = window.open('/some/url');
newWin.onunload = function(){
  // DOM unloaded, so the window is likely closed.
}

Thanks ajm looks great. Is there anyway to get the url of a popup by any chance?

This won't work cross browser. You need to handle the unload event in the pop-up.

Unload fires with every new request, not just when the window closes.

Yeah, YMMV with unload. Likely, you'll need a combination of unload and beforeunload to cover the IEs. @Josh - Unload should fire whenever the Document of the child window unloads from the browser independent of requests; what behavior are you seeing?

For instance, if there are hyperlinks within the popup window, clicking them will fire unload.

jquery - is it possible to open a popup with javascript and then detec...

javascript jquery popup
Rectangle 27 0

The only way i can think of at the moment is to create a function on your parent page that has a timeout in it which calls itself after 10 seconds. In the function you could also check for the value of a cookie to see whether it's true or false. When the popup window closes set a cookie to true.

jquery - is it possible to open a popup with javascript and then detec...

javascript jquery popup
Rectangle 27 0

I put the following javascript in the page header and it seems to work. It detects when the browser does not support showModalDialog and attaches a custom method that uses window.open, parses the dialog specs (height, width, scroll, etc.), centers on opener and sets focus back to the window (if focus is lost). If you are passing window args to the modal you will need to write some additional code to fix that. The popup is not modal but at least you don't have to change a lot of code. Might need some work for your circumstances.

<script type="text/javascript">

  // fix for deprecated method in Chrome 37
  if (!window.showModalDialog) {
     window.showModalDialog = function (arg1, arg2, arg3) {

        var w;
        var h;
        var resizable = "no";
        var scroll = "no";
        var status = "no";

        // get the modal specs
        var mdattrs = arg3.split(";");
        for (i = 0; i < mdattrs.length; i++) {
           var mdattr = mdattrs[i].split(":");

           var n = mdattr[0];
           var v = mdattr[1];
           if (n) { n = n.trim().toLowerCase(); }
           if (v) { v = v.trim().toLowerCase(); }

           if (n == "dialogheight") {
              h = v.replace("px", "");
           } else if (n == "dialogwidth") {
              w = v.replace("px", "");
           } else if (n == "resizable") {
              resizable = v;
           } else if (n == "scroll") {
              scroll = v;
           } else if (n == "status") {
              status = v;
           }
        }

        var left = window.screenX + (window.outerWidth / 2) - (w / 2);
        var top = window.screenY + (window.outerHeight / 2) - (h / 2);
        var targetWin = window.open(arg1, arg1, 'toolbar=no, location=no, directories=no, status=' + status + ', menubar=no, scrollbars=' + scroll + ', resizable=' + resizable + ', copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
        targetWin.focus();
     };
  }

javascript - showmodaldialog definition from Chromium source code - St...

javascript git google-chrome chromium
Rectangle 27 0

I put the following javascript in the page header and it seems to work. It detects when the browser does not support showModalDialog and attaches a custom method that uses window.open, parses the dialog specs (height, width, scroll, etc.), centers on opener and sets focus back to the window (if focus is lost). Also, it uses the URL as the window name so that a new window is not opened each time. If you are passing window args to the modal you will need to write some additional code to fix that. The popup is not modal but at least you don't have to change a lot of code. Might need some work for your circumstances.

<script type="text/javascript">

  // fix for deprecated method in Chrome 37
  if (!window.showModalDialog) {
     window.showModalDialog = function (arg1, arg2, arg3) {

        var w;
        var h;
        var resizable = "no";
        var scroll = "no";
        var status = "no";

        // get the modal specs
        var mdattrs = arg3.split(";");
        for (i = 0; i < mdattrs.length; i++) {
           var mdattr = mdattrs[i].split(":");

           var n = mdattr[0];
           var v = mdattr[1];
           if (n) { n = n.trim().toLowerCase(); }
           if (v) { v = v.trim().toLowerCase(); }

           if (n == "dialogheight") {
              h = v.replace("px", "");
           } else if (n == "dialogwidth") {
              w = v.replace("px", "");
           } else if (n == "resizable") {
              resizable = v;
           } else if (n == "scroll") {
              scroll = v;
           } else if (n == "status") {
              status = v;
           }
        }

        var left = window.screenX + (window.outerWidth / 2) - (w / 2);
        var top = window.screenY + (window.outerHeight / 2) - (h / 2);
        var targetWin = window.open(arg1, arg1, 'toolbar=no, location=no, directories=no, status=' + status + ', menubar=no, scrollbars=' + scroll + ', resizable=' + resizable + ', copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
        targetWin.focus();
     };
  }

javascript - How can I make window.showmodaldialog work in chrome 37? ...

javascript jquery asp.net google-chrome cross-browser
Rectangle 27 0

There is a very simple solution to your problem.

First make a new object which will open up a pop like this :

var winObj = window.open('http://www.google.com','google','width=800,height=600,status=0,toolbar=0');

In order to know when this popup window is closed, you just have to keep checking this with a loop like the following :

var loop = setInterval(function() {   
    if(winObj.closed) {  
        clearInterval(loop);  
        alert('closed');  
    }  
}, 1000);

Now you can replace alert with any javascript code you want.

jquery - is it possible to open a popup with javascript and then detec...

javascript jquery popup
Rectangle 27 0

I put the following javascript in the page header and it seems to work. It detects when the browser does not support showModalDialog and attaches a custom method that uses window.open, parses the dialog specs (height, width, scroll, etc.), centers on opener and sets focus back to the window (if focus is lost). Also, it uses the URL as the window name so that a new window is not opened each time. If you are passing window args to the modal you will need to write some additional code to fix that. The popup is not modal but at least you don't have to change a lot of code. Might need some work for your circumstances.

<script type="text/javascript">

  // fix for deprecated method in Chrome 37
  if (!window.showModalDialog) {
     window.showModalDialog = function (arg1, arg2, arg3) {

        var w;
        var h;
        var resizable = "no";
        var scroll = "no";
        var status = "no";

        // get the modal specs
        var mdattrs = arg3.split(";");
        for (i = 0; i < mdattrs.length; i++) {
           var mdattr = mdattrs[i].split(":");

           var n = mdattr[0];
           var v = mdattr[1];
           if (n) { n = n.trim().toLowerCase(); }
           if (v) { v = v.trim().toLowerCase(); }

           if (n == "dialogheight") {
              h = v.replace("px", "");
           } else if (n == "dialogwidth") {
              w = v.replace("px", "");
           } else if (n == "resizable") {
              resizable = v;
           } else if (n == "scroll") {
              scroll = v;
           } else if (n == "status") {
              status = v;
           }
        }

        var left = window.screenX + (window.outerWidth / 2) - (w / 2);
        var top = window.screenY + (window.outerHeight / 2) - (h / 2);
        var targetWin = window.open(arg1, arg1, 'toolbar=no, location=no, directories=no, status=' + status + ', menubar=no, scrollbars=' + scroll + ', resizable=' + resizable + ', copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
        targetWin.focus();
     };
  }

javascript - How can I make window.showmodaldialog work in chrome 37? ...

javascript jquery asp.net google-chrome cross-browser
Rectangle 27 0

If you have control over the contents of the pop-up, handle the window's unload event there and notify the original window via the opener property, checking first whether the opener has been closed. Note this won't always work in Opera.

window.onunload = function() {
    var win = window.opener;
    if (!win.closed) {
        win.someFunctionToCallWhenPopUpCloses();
    }
};

Since the unload event will fire whenever the user navigates away from the page in the pop-up and not just when the window is closed, you should check that the pop-up has actually closed in someFunctionToCallWhenPopUpCloses:

var popUp = window.open("popup.html", "thePopUp", "");
function someFunctionToCallWhenPopUpCloses() {
    window.setTimeout(function() {
        if (popUp.closed) {
            alert("Pop-up definitely closed");
        }
    }, 1);
}

If you don't have control over the contents of the pop-up, or if one of your target browsers does not support the unload event, you're reduced to some kind of polling solution in the main window. Adjust interval to suit.

var win = window.open("popup.html", "thePopUp", "");
var pollTimer = window.setInterval(function() {
    if (win.closed !== false) { // !== is required for compatibility with Opera
        window.clearInterval(pollTimer);
        someFunctionToCallWhenPopUpCloses();
    }
}, 200);

I recommend the polling solution instead of the unload event since it is compatible with more browsers (see opera-bugs.jottit.com).

@JonathonHill: Agreed. I alluded to the Opera problem earlier in the answer, but I should have made the point more clearly. Thanks for the edit. Btw, what's the reason for requiring window.closed !== false in Opera?

It is a workaround for a bug in Opera. I discovered it from opera-bugs.jottit.com.

@JonathonHill: Yes, I read the page. I was hoping for more detail. Don't worry, I'll look it up.

'closed' property is not a part of DOM specification.

jquery - is it possible to open a popup with javascript and then detec...

javascript jquery popup
Rectangle 27 0

To open a new window call:

var wnd = window.open("file.html", "youruniqueid", "width=400, height=300");
onunload
wnd.onunload = function(){
    // do something
};

If you want a confirmation from the user before the can close it, use onbeforeunload.

wnd.onbeforeunload = function(){
    return "are you sure?";
};

This won't work cross browser. You need to handle the unload event in the pop-up document.

Unload fires with every new request, not just when the window closes.

jquery - is it possible to open a popup with javascript and then detec...

javascript jquery popup
Rectangle 27 0

The trick is to have a JS function in your parent page that you plan to call when the popup is closed, then hook the unload event in the popup.

The window.opener property refers to the page that spawned this popup.

For example, if I wrote a function named callingPageFunction on my original page, I would call it from the popup like this:

$(window).unload(function() {
    window.opener.callingPageFunction()
});
  • This should be wrapped in a ready function.
  • I have an anonymous function because you may want other logic in there

jquery - is it possible to open a popup with javascript and then detec...

javascript jquery popup
Rectangle 27 0

The truth is that you can't. You need to own both sides, or speak with the other party to set up a policy; use the same domain; or have the user use an older/less secure browser.

You could however get the 'likes' from someone by using Facebook's API, given the privacy options from the user of course.

The sites you mentioned, and other sites that collect user data (annoying IMO) do so by having the owner of the website implement part of their code (like i.po.st does on Explosm.net). They offer a solution such as adding "Sharing" options, meanwhile they collect user data. It's not very different to what Google does with Analytics.

Another way they use is by adding advertisement, not only they profit from advertising, but they also collect user data. So let's suppose Company A pays thousands of websites to show advertisements (like Google Ads). This website would be able to get information from a LOT of users from a LOT of websites, by showing their ads, and adding tracking code (shameless evil creatures). They either use it to show more interesting advertisement, sell it, or share it with other similar sites, and form a network of evil doers who invade your privacy for "targeted advertising".

Then, How social exchange sites like addmefast and like4like are fetching the information without using facebook api?. I can't find how they are doing.

php - Is there any way to detect user clicks in the javascript popup? ...

javascript php jquery javascript-events
Rectangle 27 0

I put the following javascript in the page header and it seems to work. It detects when the browser does not support showModalDialog and attaches a custom method that uses window.open, parses the dialog specs (height, width, scroll, etc.), centers on opener and sets focus back to the window (if focus is lost). Also, it uses the URL as the window name so that a new window is not opened each time. If you are passing window args to the modal you will need to write some additional code to fix that. The popup is not modal but at least you don't have to change a lot of code. Might need some work for your circumstances.

<script type="text/javascript">

  // fix for deprecated method in Chrome 37
  if (!window.showModalDialog) {
     window.showModalDialog = function (arg1, arg2, arg3) {

        var w;
        var h;
        var resizable = "no";
        var scroll = "no";
        var status = "no";

        // get the modal specs
        var mdattrs = arg3.split(";");
        for (i = 0; i < mdattrs.length; i++) {
           var mdattr = mdattrs[i].split(":");

           var n = mdattr[0];
           var v = mdattr[1];
           if (n) { n = n.trim().toLowerCase(); }
           if (v) { v = v.trim().toLowerCase(); }

           if (n == "dialogheight") {
              h = v.replace("px", "");
           } else if (n == "dialogwidth") {
              w = v.replace("px", "");
           } else if (n == "resizable") {
              resizable = v;
           } else if (n == "scroll") {
              scroll = v;
           } else if (n == "status") {
              status = v;
           }
        }

        var left = window.screenX + (window.outerWidth / 2) - (w / 2);
        var top = window.screenY + (window.outerHeight / 2) - (h / 2);
        var targetWin = window.open(arg1, arg1, 'toolbar=no, location=no, directories=no, status=' + status + ', menubar=no, scrollbars=' + scroll + ', resizable=' + resizable + ', copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
        targetWin.focus();
     };
  }

javascript - How can I make window.showmodaldialog work in chrome 37? ...

javascript jquery asp.net google-chrome cross-browser
Rectangle 27 0

jQuery isn't the solution to every problem :).

True, true. I should have begun my answer with the word "if" as in "If you can use the jQuery UI Dialog" and not just assumed it was possible. Hey! Wait a second...

And, when it comes to JavaScript, jQuery is never really a solution to problems, but is often a huge, HUGE, HUGE shortcut to the solution, whatever it may be. You learn more by taking the scenic route, but, in many cases, I and most people prefer the (huge, HUGE, HUGE ) jQuery shortcut.

jquery - is it possible to open a popup with javascript and then detec...

javascript jquery popup
Rectangle 27 0

What are you trying to accomplish, exactly? Are you trying to detect if the current window is a popup? If so, BornToCode's response in this thread might be your answer. He suggests to test if window.opener is defined:

if ( window.opener !== 'undefined' )

What i am trying to accomplish is, if the user agent(iphone, web, android,...) supporting popup, then i will call function A. if it's not supporting pop e.g iphone, to call function B.

I understand. I think testing for that is kind of a catch 22, so I don't know how you could accomplish this natively. That being said, I know you were trying to accomplish this with native JS only, but have you considered using jQuery + jQuery UI Dialog? That way, your script would be able to respond in the same manner for all user agents and bypass the popup test altogether.

Thanks for the response, however native JS is a requirement for this implementation

javascript - detect if the useragent supports popup - Stack Overflow

javascript popup
Rectangle 27 0

you can try this script:

<Script>
var windowName = 'userConsole'; 
var popUp = window.open('/popup-page.php', windowName, 'width=1000, height=700, left=24, top=24, scrollbars, resizable');
if (popUp == null || typeof(popUp)=='undefined') {  
    alert('Please disable your pop-up blocker and click the "Open" link again.'); 
} 
else {  
    popUp.focus();// this will open popup if the browser allow it.you can do your implementation on popup support here
}
</script>

With this approach it will detect if the browser blocking the popup or not. What i am looking for is if the current device(web, iphone, android,ipad) is supporting popop. for example if i am using chrome in web and the popup is not blocked, and i call window.open it will open a popup. however in Iphone, if i use window.open it will open new tab and not popup. so what i am looking for is whether the current user agent(iphone, android,ipad,web) is supporting popup or it will open new tab instead of popup.

javascript - detect if the useragent supports popup - Stack Overflow

javascript popup
Rectangle 27 0

You'll be bound by all the usual same origin policies, and I'd recommend reading up on them directly: http://en.wikipedia.org/wiki/Same_origin_policy . In short, you're trying to do cross-domain communication, which is prohibited by the browser's security model. To get around it, there are server-side proxies, JSONP, Flash, document.domain (but only if it's two different subdomains), and a bevy of hacks that work with varying success depending on your support requirements and what exactly you're trying to do.

Can you tell us more about what your browser support requirements are? Can you use XHR Level 2? What's the page you're trying to load in the popup?

javascript - How do you detect if a popup to another domain was blocke...

javascript google-chrome popupwindow