Link in popup window does not close the window? - javascript

I have this bit of html code, but when I click the link, it does not close:
<html>
<head>
<title></title>
</head>
<body>
<h2>Members Only</h2>
<p>You must be a member.</p>
<p>Please Sign In or Create an Account.</p>
Close this Window
</body>
</html>

I just removed the spaces and it works well :
Close this Window

Popups suck, use a modal dialog instead, especially for something as simple as a notification.
That being said, try this:
Close this Window

Related

Cannot open a separate window as an underlying tab in HTML

I am trying to open a separate window (as an underlying window) of the current window. I have attached a simple code segment which I used. But in Chrome there is a popup blocked message appeared when I do this. It means that The separate window is not recognized as a window, it still considered as a popup. How can I do this ? Any suggestions would be really appreciated
<html>
<head>
<title>JS Window example</title>
</head>
<script type="text/javascript">
function windowonload()
{
window.open("http://yahoo.com", "sameera", "height=200,width=200");
}
</script>
<body onload="javascript: windowonload()">
<h1>JS Window example</h1>
</body>
</html>
you can use iframe tag like this wherever you want to show the window
<iframe src="http://yahoo.com"></iframe>

Javascript window close

I need to get a custom alert box when user clicks on 'X' (window close).
User is given 'OK' and 'Cancel' button options
OK button closes the window. Cancel button cancels the close action
I think you may find your answer on this post which looks similar - javascript confirm dialog box before close browser window
You have to show what you have done so far
Html code
<html>
<head>
<script type="text/javascript">
window.onbeforeunload = function() {
return "Did you save your stuff?"
}
</script>
</head>
<body>
</body>
</html>

Is it possible to take the FB share dialog and after a user has shared, to then post a message to the users?

For example, the dialog below will open a new window to share from. After the window is closed out because the user has shared the post. Could you then do a overlay message from the original url using javascript?
http://www.upworthy.com/if-you-live-in-one-of-these-states-the-impact-of-washingtons-shenanigans-is-huge
The site above does something like this, just not sure how. If you click on share to facebook and then "x" out of the box, you'll see a overlay that happens after a user has either shared or closed the window. Is this done with javascript, if so how?
<a class="shareonfb" style="color: #fff;text-indent: 0px;padding-left: 35px;width: 130px;padding-top: 10px;height: 24px;" onClick="window.open (this.href, 'child', 'height=400,width=665,scrollbars'); return false" href="https://www.facebook.com/sharer/sharer.php?u=http://foo.com" target="_blank">Share on Facebook</a>
create a html file "parent.html" and put the code:
<!DOCTYPE html>
<html>
<head>
<script>
function open_win()
{
myWindow=window.open('popup.html','','width=300,height=250');
myWindow.focus();
myWindow.onbeforeunload = WindowCloseHanlder;
}
function WindowCloseHanlder(){
myWindow.close();
window.alert('Popup is closed');
}
</script>
</head>
<body>
<h1>Welcome to my Home Page</h1>
Share on Facebook
</body>
</html>
create "popup.html" and put this code:
<!DOCTYPE html>
<html>
<head></head>
<body>
<h1>I am pop up</h1>
<p>Close this window</p>
</body>
</html>
You will see the javascript call after you close the popup window. Instead of alert message you can call your popup.

How to call a function when close popup window

I am calling the Javascript window.open() function to load another url in a pop up window.
When the users closes the popup window, I want the MyThanks() function to be called. How I can do this?
My Script :
<!DOCTYPE html>
<html>
<head>
<script>
function openWin(){
myWindow=window.open('http://facebook.com/ekwebhost','','width=600,height=400,left=200');
myWindow.focus();
}
function MyThanks(){
alert("Thanks");
}
</script>
</head>
<body>
<input type="button" value="Open window" onclick="openWin()" />
</body>
</html>
Regarding usage of popups:
Are you aware that Facebook & Twitter still use popup windows for user like & follow. Go to http://www.ekwebhost.com and click the Facebook "Like" button or the Twitter "Follow" button. Why can't I use popup windows for my own needs?
function openWin(){
myWindow=window.open('http://facebook.com/ekwebhost','','width=600,height=400,left=200');
// Add this event listener; the function will be called when the window closes
myWindow.onbeforeunload = function(){ alert("Thanks");};
myWindow.focus();
}
Try this!
You can swap out the function(){ alert("Thanks");}; for MyThanks to call your function.
The new window that you open will have an attribute called opener that references the Window object that created it. You can then call functions on the parent window by calling window.opener.MyThanks();
Popup:
<script type="text/javascript">
function closePopup() {
window.opener.MyThanks();
window.close();
}
</script>
<div>
<h1>My Popup</h1>
<!-- Form or info to display -->
<button onclick="closePopup();">Close</button>
</div>
While there is nothing inherently wrong with browser popup windows, they can be annoying since the user can lose them behind other windows. Also, it takes their focus off of your page to do something else. The application that I currently develop is trying to move all of our popup windows to Javascript dialogs. It gets pretty annoying for users once you get 3 popups deep.
There are a bunch of ways to create dialogs within your webpage. jQuery UI is one library that I like.
You can try this:
<script>
function openWin() {
myWindow = window.open('http://facebook.com/ekwebhost', '', 'width=600,height=400,left=200');
myWindow.focus();
MyThanks();
}
function MyThanks() {
alert("Thanks");
}
</script>

Popup window in Javascript

In Javascript, I want to open my window.html file in a popup window. But it doesn't display any text. Just a blank page.
This is index.html:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<script language="javascript">
var newwindow;
function popit(url){
newwindow = window.open(
url, '', "status=yes, height=500; width=500; resizeable=0");
}
</script>
</head>
<body>
CLICK ME!
</body>
</html>
window.html:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>SAMPLE TEXT</p>
</body>
</html>
Why doesn't it display any text?
javascript:popit(window.html);
Replace with:
javascript:popit('window.html');
Your click handler code is syntactically incorrect:
CLICK ME!
Always, always have your developer console open to check for JavaScript errors! (edit — actually in this case there wouldn't have been an error; window.html would resolve to undefined probably! Still, keep the console open :-)
Also note that I used an "onclick" attribute instead of "href".
A GOOD working code with NO crashes.
Simple and what makes this code better is that you can use it in a JavaScript file separately and have it fairing to more then one file with the same popup size even though its different pages on popups.
Javascript
// Popup window code
function MyPopUp(url) {
popupWindow = window.open(
url,'popUpWindow','height=454,width=580,left=0,top=200,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
HTML
My PopUp
NOTE: You can also use this as onload in body for example <body onload="JavaScript:MyPopUp('MyDirectory/Page.html');"> and it will aslo work on onmouseover and others... though I do not advise this unless you want to piss off the clients visiting your page.

Categories