This question already has answers here:
Check if a popup window is closed
(5 answers)
Closed 7 years ago.
I need to attach some event to my popup while my window is being closed and I can't figure out how to do this.
$scope.loginWithOk = function() {
var left, popup, top;
$window.$scope = $scope;
left = screen.width / 2 - 250;
top = screen.height / 2 - 250;
popup = $window.open('/auth/odnoklassniki', '', 'top=' + top + ',left=' + left + ',width=700,height=500');
};
How can I do this?
When I go with
popup.onclose = function() {
return alert(2222222222);
};
I can't see any alert so this option doesn't seem to be working.
You can try using window.onunload
https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onunload
More details as requested:
popup.onunload = function() {
return alert(2222222222);
}
Related
This question already has answers here:
Center a popup window on screen?
(19 answers)
Closed 5 years ago.
I found the following JavaScript code many years ago (between 8 and 10 years ago, I think) though I can't remember where or when. I use it to make popup windows with answers for a Jeopardy review game for my French students. I dabble a little bit but I don't know very much beyond the absolute basics about coding (I do know how to change the background color in this code and the window size, for example). I would like to have the popup window be centered in the middle of the page rather than opening in the upper left of the window.
I've seen code bits in response to other questions (Center a popup window on screen? for example) that look like they should make that happen but when I've tried adding them in different places to my existing code it always makes the feedback window no longer open. I don't know enough about coding to know what of that code I need or where to put it. I have tried pulling the VAR lines and adding them to the existing code but as I have said, it disables the popup window completely.
Can someone help me tell me if it is possible to modify this code to center the popup window in the middle of the page or if I should try to find a different code to make that happen?
Thank you for your help.
Shannon
Here is the code that I have:
function feedback(message) {
var browser = navigator.appName;
var browserVersion = navigator.appVersion;
if ((browser.indexOf ("Netscape") >= 0) || (browser.indexOf ("Explorer") >= 0)) {
// This function opens a new window with the message text.
// The window will disappear when it loses focus.
msgWindow=window.open('','msgWindow','toolbar=no,location=no,directories=no, status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=210,height=180');
msgWindow.document.open();
msgWindow.focus();
msgWindow.document.write("<HEAD><TITLE>message</TITLE>");
msgWindow.document.write("</HEAD>");
msgWindow.document.write
("<BODY BGCOLOR='#FAE080' onblur='window.close()'>");
msgWindow.document.write
("<P><CENTER><FONT SIZE=+1><B>" + message + "</FONT></B></P></CENTER>");
msgWindow.document.write("</BODY>");
msgWindow.document.close();
} else { // Not Netscape or Internet Explorer
alert(message);
}
} // end of JavaScript Function feedback
It is not working here in code snippet but you can check this fiddle Check this
function myFunction() {
var pageURL="http://google.com";
var w = 500;
var h = 500;
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
window.open("https://www.google.com",'','width=' + w +', height='+h +',top='+top+',left='+left);
}
<button onclick="myFunction()">Click Here</button>
Your modified Code Will be like this Check updated Fiddle
function feedback(message) {
var browser = navigator.appName;
var browserVersion = navigator.appVersion;
if ((browser.indexOf ("Netscape") >= 0) || (browser.indexOf ("Explorer") >= 0)) {
// This function opens a new window with the message text.
// The window will disappear when it loses focus.
var w = 210;
var h = 190;
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var msgWindow=window.open("",'','width=' + w +', height='+h +',top='+top+',left='+left);
msgWindow.document.open();
msgWindow.focus();
msgWindow.document.write("<HEAD><TITLE>message</TITLE>");
msgWindow.document.write("</HEAD>");
msgWindow.document.write("<BODY BGCOLOR='#FAE080' onblur='window.close()'>");
msgWindow.document.write("<P><CENTER><FONT SIZE=+1><B>" + message + "</FONT></B></P></CENTER>");
msgWindow.document.write("</BODY>");
msgWindow.document.close();
} else { // Not Netscape or Internet Explorer
alert(message);
}
} // end of JavaScript Function feedback
This question already has answers here:
JavaScript animated smooth-scroll
(2 answers)
Closed 5 years ago.
In my page footer I have a "Back to Top" button which instantly jumps to the top of the page. How can I make it so it scrolls fast to the top instead?
you can add these javascript functions:
function ScrollTo(name) {
ScrollToResolver(document.getElementById(name));
}
function ScrollToResolver(elem) {
var jump = parseInt(elem.getBoundingClientRect().top * .2);
document.body.scrollTop += jump;
document.documentElement.scrollTop += jump;
if (!elem.lastjump || elem.lastjump > Math.abs(jump)) {
elem.lastjump = Math.abs(jump);
setTimeout(function() {
ScrollToResolver(elem);
}, "100");
} else {
elem.lastjump = null;
}
}
and than on the button add this function call:
<button onclick="ScrollTo('top')">Back to Top</button>
where the very forst element of the content has class "top"
This question already has answers here:
How do I make text inside the title tag animate using JavaScript?
(4 answers)
Closed 5 years ago.
How do I animate site title of site in browser tab like this?
Screen capture GIF:
You can add a scroll animation to the title of your browser tab using this Javascript code:
msg = "Title";
msg = " ...Just a scrolling title example" + msg;position = 0;
function scrolltitle() {
document.title = msg.substring(position, msg.length) + msg.substring(0, position); position++;
if (position > msg.length) position = 0
window.setTimeout("scrolltitle()",170);
}
scrolltitle();
use window.setTimeout() or window.setInterval() and change document.title
This is pure js...
function recursiveAnimateTitle(string) {
let firstLetter = string[0];
let title = document.querySelector('title');
title.innerHTML += firstLetter;
if (string.length > 1) {
setTimeout(function() {
recursiveAnimateTitle(string.substring(1));
}, 100);
}
}
function animateTitle(string) {
document.querySelector('title').innerHTML = "";
recursiveAnimateTitle(string);
}
animateTitle('Example Title');
<head>
<title>Some Default Title</title>
</head>
<body></body>
If you want to vary the time for each letter, use math.random with a range.
With a distribution if you want to get really weird with it.
This question already has answers here:
How can change a styling of javascript alert button?
(3 answers)
Closed 9 years ago.
how to do a javascript alert box that contain a button with a class like this submit button:
<input type="submit" class="lightbox">
or there is any way to make a javascript form that pop up and contain this submit button?
I would use this code:
var doc = document, htm = doc.documentElement, bod = doc.body;
function E(e){
return doc.getElementById(e);
}
function winOpen(clickId, url, name, height, width){
var ht = innerHeight || htm.clientHeight || bod.clientHeight;
var wd = innerWidth || htm.clientWidth || bod.clientWidth;
ht = (height-ht)/2; wd = (width-wd)/2;
E(clickId).onclick = function(){
open(url, name, 'height='+height+',width='+width+',top='+ht+',left='+wd);
}
}
// You would use this like
winOpen('newWindow', 'wherever.html', 'windowName', 500, 500);
whatever.html should be the page with your lightbox class.
Standard browser alerts are not stylable - it will have to be done in code. If you don't want to window.open a new page and willing to use a 3rd party library - jQueryUI is a good choice. The Dialog is fully stylable- yes, including button.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to detect overflow in div element?
Is there a cross-browser way to listen to div overflow?
Something like: $('#myDiv').bind("divOverflow", function(){alert('div overflowed!')})
You can do that by comparing scrollHeight with clientHeight.
<script type="text/javascript">
function GetContainerSize ()
{
var container = document.getElementById ("tempDiv");
var message = "The width of the contents with padding: " + container.scrollWidth + "px.\n";
message += "The height of the contents with padding: " + container.scrollHeight + "px.\n";
alert (message);
}
</script>
For more info: How to detect overflow in div element?
You could set an interval and check if the element's scrollHeight > offsetHeight. There is no built-in event for this.