Detect blocked popups
This commit is contained in:
19
auth.php
19
auth.php
@ -80,7 +80,7 @@ function getAuthorizationCode( $url ){
|
||||
|
||||
// open an authentication request window (to spotify)
|
||||
var popup = window.open("<?php echo $popup ?>","popup","height=680,width=400");
|
||||
|
||||
|
||||
// listen for incoming messages from the popup
|
||||
window.addEventListener('message', function(event){
|
||||
|
||||
@ -93,12 +93,17 @@ function getAuthorizationCode( $url ){
|
||||
}, false);
|
||||
|
||||
var timer = setInterval(checkPopup, 1000);
|
||||
function checkPopup(){
|
||||
if( popup.closed ){
|
||||
window.parent.postMessage( 'closed', '*' );
|
||||
clearInterval(timer);
|
||||
}
|
||||
}
|
||||
function checkPopup(){
|
||||
if( typeof(popup) !== 'undefined' && popup ){
|
||||
if( popup.closed ){
|
||||
window.parent.postMessage( 'closed', '*' );
|
||||
clearInterval(timer);
|
||||
}
|
||||
}else{
|
||||
window.parent.postMessage( 'blocked', '*' );
|
||||
clearInterval(timer);
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
<?php
|
||||
|
||||
@ -29,12 +29,14 @@ class SpotifyAuthenticationFrame extends React.Component{
|
||||
// listen for incoming messages from the authorization iframe
|
||||
// this is triggered when authentication is granted from the popup
|
||||
window.addEventListener('message', function(event){
|
||||
|
||||
|
||||
if(event.data == 'closed'){
|
||||
self.setState({
|
||||
frameUrl: '//jamesbarnsley.co.nz/auth.php?action=frame',
|
||||
authorizing: false
|
||||
})
|
||||
}else if(event.data == 'blocked'){
|
||||
self.props.uiActions.createNotification('Popup blocked. Please allow popups and try again.','bad')
|
||||
}else{
|
||||
|
||||
// only allow incoming data from our authorized authenticator proxy
|
||||
@ -59,7 +61,6 @@ class SpotifyAuthenticationFrame extends React.Component{
|
||||
frameUrl: '//jamesbarnsley.co.nz/auth.php?action=authorize&app='+location.protocol+'//'+window.location.host,
|
||||
authorizing: true
|
||||
})
|
||||
this.props.uiActions.createNotification('No popup? Your browser may have blocked it...')
|
||||
}
|
||||
|
||||
renderAuthorizeButton(){
|
||||
|
||||
Reference in New Issue
Block a user