I'm needing open a window behind parent window, and I'm not finding anything to do that.
Could someone help me with this code or tips?
Parent.php
<script type="text/javascript">
$(document).ready(function () {
window.name = "parent";
$('#link').click(function (event){
event.preventDefault();
window.open('child.php', 'fullscreen=yes', 'scrollbars=auto');
});
});
</script>
<body>
<a id="link" href="/">Open Window </a>
</body>
child.php
<script type="text/javascript">//<![CDATA[
$(document).ready(function () {
$('#link').click(function(event){
event.preventDefault();
console.log(window.opener.location);
var goBack = window.open('', 'parent');
goBack.focus();
});
});//]]>
</script>
<body>
<a id="link" href="#">Return to Parent </a>
</body>
LINK CODE: http://pontodosjogos.com/testegrana.php
You can use this code to display a pop-under window:
<script>
//specify page to pop-under
var popunder="http://yahoo.com";
//specify popunder window features
//set 1 to enable a particular feature, 0 to disable
var winfeatures="width=800,height=510,scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0";
function loadpopunder()
{
win2=window.open(popunder,"",winfeatures);
win2.blur();
window.focus();
}
loadpopunder();
</script>
Source: http://www.javascriptkit.com/script/script2/popunder.shtml
Keep in mind that browsers will likely block the pop-under window and it is generally annoying seeing those from a user's perspective so try to not overdo those.
Related
I know this question has been "answered" multiple times, but nothing works in my case. I have tried with focus(),blur(). ect...I am using IE 11. Anyone have any idea? I want to open a new window, but keep focus on the original window....
btn.addEventListener("click", function (ev) {
var url = "https://XXXX/XXXXX/XXXXXX/";
var newWin = window.open(url, "_blank");
window.focus();
ev.stopPropagation();
}, true);
Try to refer example below may work for you.
Code in parent page.
<html>
<head>
<script language="JavaScript" type="text/javascript">
function openPopUP() {
window.open('C:\\Users\\Administrator\\Desktop\\95.html','NewWin',
'toolbar=no,status=no,width=350,height=135')
}
</script>
</head>
<body>
Original Page:<br>
Click to open popup
</body>
</html>
Code in child page.
<html>
<head>
<script>
function abc()
{
window.parent.opener.focus();
}
</script>
</head>
<body onLoad="abc()">
child page
</body>
</html>
In JavaScript, 'onbeforeunload' not working until we clicked on opened window.
Please suggest me any solution.
Thanks in advance
Based on your comment, I don't think you're using it correctly. You need to return a string, not use an alert.
Parent page:
<script>
var w;
function x(){
w = window.open('test2.html');
}
</script>
<button onclick="x();">open</button>
<button onclick="w.close();">close</button>
Popup:
<html>
<head>
<script>
window.onbeforeunload=function (e) {
e.returnValue = "Are you sure you want to leave this page?";
return e.returnValue;
}
</script>
</head>
<body>
popup
</body>
</html>
Hi Teams from all around,
I am most stumped on this issue.
I am attempting to use color box to create a pop up of a url through an iframe. (please not that the creative and source I have are the test pages, not actual subject). I am looking to have the iframe close after 12 seconds unless someone click within the iframe on the images within.
Basically it is a floater that will be for things such as group newsletters. I want to be able to just switch out the source page and have it available when the page first loads.
So, the page loads, starts the iframe floater, closes after (x) seconds unless someone clicks anywhere on the iframe, at that point they have to hit the close button.
I have been working on this for 2 days, and I either have it where the floater does not close at all or the floater refuses to stay open.
Please help.
And Much thanks in advance.
Preview Page:
http://matthewsallansdesign.com/Scripps/TestPageSETUP.html
Code on Parent Page:
<link rel="stylesheet" href="http://matthewsallansdesign.com/Scripps/images/colorbox.css">
<script src="http://matthewsallansdesign.com/Scripps/images/jquery.min.js"></script>
<script src="http://matthewsallansdesign.com/Scripps/images/jquery.colorbox-min.js"></script>
<script>
Var t;
window.onload = $(document).ready(function(){
$(".iframe").colorbox({iframe:true, width:"95%", height:"95%", open:true, opacity:.2, overlayClose:false, escKey:false, closeButton:true, reposition:true});
});
</script><script>
window.onload = $(document).bind('cbox_complete', function(){
t = setTimeout($.colorbox.close, 12000);
});
</script><script>
$(".iframe").click(function(){
alert("click");
clearTimeout(t);
};
</script>
<a class='iframe' href="http://matthewsallansdesign.com/Scripps/testPageA.html"></a>
Code on Child Page:
<script type="text/javascript">
$('body').click(function(){
parent.postMessage('alert','moooo');
});
</script>
<img src="http://matthewsallansdesign.com/imgCreativeContent/imgExpanded/creative/grassSet3.png" />
Thanks,
I actually was semi close before.
Here is how I did it. I am leaving this here for future people to learn from and have a very easy time.
Allowing the future web developers to learn.
Parent:
<link rel="stylesheet" href="http://matthewsallansdesign.com/Scripps/images/colorbox.css">
<script src="http://matthewsallansdesign.com/Scripps/images/jquery.min.js"></script>
<script src="http://matthewsallansdesign.com/Scripps/images/jquery.colorbox-min.js"></script>
<script>
var t;
var iframeHost = "http://matthewsallansdesign.com"
if(typeof window.postMessage != 'undefined'){
var iframeListener = function (event) {
console.log(event);
if(iframeHost == event.origin){
clearTimeout(t);
}
}
if (window.addEventListener) {
addEventListener("message", iframeListener, false);
}
else {
attachEvent("onmessage", iframeListener);
}
}
window.onload = $(document).ready(function(){
$(".iframe").colorbox({iframe:true, width:"95%", height:"95%", open:true, opacity:.2, overlayClose:false, escKey:false, closeButton:true, reposition:true});
});
window.onload = $(document).bind('cbox_complete', function(){
t = setTimeout($.colorbox.close, 6000);
});
</script>
<a class='iframe' href="http://matthewsallansdesign.com/Scripps/testPageA.html"></a>
Child:
<script type="text/javascript">
$('body').click(function(){
parent.postMessage("HAMPSTERS",'*');
});
</script>
<img src="http://matthewsallansdesign.com/imgCreativeContent/imgExpanded/creative/grassSet3.png">
The only thing anyone needs to actually do with this is replace the urls above.
I recommend everyone download the js and css on their own servers.
I will leave it up so others can find it.
Thanks,
Matthew
In my page a pop up window display of confirmation only when am going to close the browser/tab. It works for my page but it also ask while am going to navigate to another page. I want the pop up window when i close tab not while navigating to another page. Can anyone plz help me.
Here is code.
var PreventExitPop = false;
function ExitPop() {
if(PreventExitPop == false) {
PreventExitPop=true;
window.alert("hi!\n\click ok to go on next page");
var frm = document.forms['exitpopform'];
frm.action = 'deals.html';
frm.submit();
scroll(0, 0);
return "\n\n\n***************************************\n\n";
}
}
window.onbeforeunload = ExitPop;
</SCRIPT>
<form id='exitpopform' method='post' action='#'>
<input type='hidden' value='' />
</form>
Try Below Code for this.
<script type="text/javascript">
$(document).ready(function () {
$("a").click(function () {
window.onbeforeunload = null;
});
$(window).bind("beforeunload", function () {
return confirm("Do you really want to close?");
});
})
</script>
Above code will set NULL for onbeforeunload when any anchor tag is cliked throughout the website.
And if user will close browser/tab than it will raise the onbeforeunload function and it will show the popup with warning message.
For this this function you have to add JQuery reference into <head> tag of you HTML page as below.
<script src="your folder name/Javascript/jquery-1.8.2.js" type="text/javascript"></script>
I have a popup window which is opened using this code:
function _openpageview(fieldid,objectid,opennew)
{
var url='/s_viewpagefield.jsp?fieldid='+fieldid+'&codedid='+objectid;
web_window = window.open(url,'_blank', 'menubar=yes,location=no,scrollbars=yes,width=800,height=600,status=no,resizable=yes,top=0,left=0,dependent=yes,alwaysRaised=yes');
web_window.opener = window;
web_window.focus();
}
How can I close that popup from within the popup?
window.close();
self.close();
web_window.close();
all did not work
An old tip...
var daddy = window.self;
daddy.opener = window.self;
daddy.close();
You can only close a window using javascript that was opened using javascript, i.e. when the window was opened using :
window.open
then
window.close
will work. Or else not.
For such a seemingly simple thing this can be a royal pain in the butt! I found a solution that works beautifully (class="video-close" is obviously particular to this button and optional)
Close this window
Your web_window variable must have gone out of scope when you tried to close the window. Add this line into your _openpageview function to test:
setTimeout(function(){web_window.close();},1000);
in my case (joomla opened popup) I had to use this:
onclick="submit(); window.parent.location.reload(false);window.parent.SqueezeBox.close();"
Hope this may help
In my case, I just needed to close my pop-up and redirect the user to his profile page when he clicks "ok" after reading some message
I tried with a few hacks, including setTimeout + self.close(), but with IE, this was closing the whole tab...
Solution :
I replaced my link with a simple submit button.
<button type="submit" onclick="window.location.href='profile.html';">buttonText</button>.
Nothing more.
This may sound stupid, but I didn't think to such a simple solution, since my pop-up did not have any form.
I hope it will help some front-end noobs like me !
try this solution
<html>
<script>
var newWindow;
function openWindow() {
newWindow = window.open("", "myWindow", "width=200,height=100");
newWindow.document.write('Close this window');
}
function closeWindow() {
newWindow.close();
}
</script>
<h3 style="color:brown"> Close Window Example </h3>
<body>
<button onclick="openWindow()">Open New Window</button>
<br><br>
<button onclick="closeWindow()">Close New Window </button>
</body>
</html>
Close a popup after print.
In the parent windows
let IframeLink = '../Sale/PriceKOT?SalesID=#(Model.SalesInfo.SalesID)&PrintTypeID=3';
var newwindow = window.open(IframeLink, "KOT Print", 'width=560,height=550,toolbar=0,menubar=0,location=0');
if (window.focus) { newwindow.focus() }
function closeThisPopUp() {
newwindow.close();
printf();
}
In the child or popup window
window.onafterprint = function (event) {
opener.closeThisPopUp();
window.close;
};
using window.close()
javascript:window.close()
Try This:
<html>
<header>
<script>
let newWebWindow;
function openPageView() {
newWebWindow = window.open("", "window", "width=200,height=100");
newWebWindow.document.write(`Close this window`);
}
function closePageView() {
newWebWindow.close();
}
</script>
</header>
<body>
<h3 style="color:brown"> Close Window Example </h3>
<button onclick="openPageView()">Open Page</button>
<button onclick="closePageView()">Close Page</button>
</body>
</html>