I have a button on my page that opens a popup window.
<div class="container-content">
<div id="VKauth">In order to leave comments, you have to authorize via VK and grant all permissions.</div><br />
<div>
<a href="/authvk"
onclick="return !window.open(this.href, 'Redirecting to VK...', 'width=500, height=500')"
target="_blank">
<object data="/images/VKAuth.png" type="image/png" class="authvk">
Authorize via VK
</object>
</a>
</div>
</div>
A popup window comes up with the authorization form in VK (social media website). If the users cancels authorization, VK redirects them to a PHP script on my website (inside the same popup window).
That script is as follows (I removed irrelevant logic):
echo "<script>parent.response = 'user_denied';</script>";
echo "<script>window.close();</script>";
I suppose at this point, before closing the window, it must pass the variable response
with the value 'user_denied'
to the parent window.
On the parent page (the same that has the button), I have a javascript as follows (uses a little of jquery):
response = {
aInternal: 10,
aListener: function(val) {},
set a(val) {
this.aInternal = val;
this.aListener(val);
},
get a() {
return this.aInternal;
},
registerListener: function(listener) {
this.aListener = listener;
}
}
response.registerListener(function(val) {
if (response.a == 'user_denied') {
console.log('response is', response.a);
$("#VKauth").append('<div style="color: red;">You denied authorization! Comments are blocked!</div>');
}
});
However, after my PHP script on the popup page finishes and, presumably, reports the variable response
with the value 'user_denied'
to the parent window, nothing happens at all. Even no errors in the console.
I used this answer to listen for variable changes. What am I doing wrong? A lot, I suppose.