hi please check the below code i am trying to open tab with name
and after that try to close that tab but unable to close
or else can anyone tell how we can close opened all tab (url1,url2) from parent tab (url) while close parent tab
error in firebug is my_window is undefined
<form name="submitForm1" target="my_window" method="POST" action="http://localhost:8080/ADDMIBREP/">
<input type="hidden" name="uname" value="uname">
ADDMIBREPORT
</form>
remove
</body>
<script>
function closepopup()
{
alert("hi");
if(false == my_window.closed)
{
my_window.close ();
}
else
{
alert('Window already closed!');
}
} <script>
remove
OR
var my_first_window = window.open('test/test.html');
var my_second_window = window.open('test/test1.html');
window.onunload = function() {
if(!my_first_window.closed)
my_first_window.close();
if(!my_second_window.closed)
my_second_window.close();
}
Heres an example of what your trying to do... http://jsfiddle.net/KjBj3/7/
var win = window.open("", "win","width=200,height=100");
win.document.write('This is myWindow! Click to close');
win.focus();
win.opener.document.write('<p>This is the source window!</p>');
Related
I'm trying to figure out how to make a play/pause functionality for my chrome extension. I've figured it out and it works however, for usability I now am trying to get the popup window to:
Keep the checkbox checked if it was before closing the popup.
Keep the content that popup.js wrote into a span tag before closing the popup.
My popup.html is:
<script src="popup.js"></script>
<div class="container">
<div class="checkbox">
<p>Check the box to pause the extension</p>
<input type="checkbox" id="switcher" name="switcher">
<p><span id="extensionStatus"></span></p>
</div>
<a id="submit" href="#">Save</a>
</div>
And my popup.js is:
document.addEventListener('DOMContentLoaded', function() {
var link = document.getElementById('submit');
link.addEventListener('click', function() {
var status;
var switcher = document.getElementById('switcher');
var updateStatus = document.getElementById("extensionStatus");
if(switcher.checked == true) {
status = "paused";
} else {
status = "play";
}
chrome.storage.sync.set({'status': status});
chrome.storage.sync.get('status', function (result) {
status = result.status;
updateStatus.innerHTML = "Current Status: " + status;
if(status == "paused") {
switcher.checked = true;
}
});
});
});
I set have to set the value in storage as I also use the value to do other code on content-script file.
Basically where the line that writes the innerHTML and then the line that sets the checkbox to checked run fine when the popup is open and then as soon as you close the popup and reopen obviously the session resets.
I know it needs something like this in the popup.js instead but I am not quite sure what to put in the function in the background.js as I can't/don't know how to access the popup DOM from background.js:
var backgroundPage = chrome.runtime.getBackgroundPage();
backgroundPage.savePopup();
I don't know how extension storage works but here's a demo which works with local storage. Maybe it can help you with the extension.
Demo
document.addEventListener('DOMContentLoaded', function() {
if (localStorage.getItem('status') == 'paused') {
switcher.checked = true;
}
var link = document.getElementById('submit');
link.addEventListener('click', function() {
var status;
var switcher = document.getElementById('switcher');
var updateStatus = document.getElementById("extensionStatus");
console.log('staus:', localStorage.getItem('status'));
if (switcher.checked == true) {
status = "paused";
} else {
status = "play";
}
localStorage.setItem('status', status);
});
});
I am trying to get the reference of the newly opened tab and use it in the same function to close the tab and reopen,
for more details:
I want to create a Java script button
on the first click open a new tab
on the second click of the same button close the tab and reopen the same tab
var Window;
// Function that open the new Window
function windowOpen() {
Window = window.open( "https://www.google.com/", "_blank", "width=400, height=450");
// if (window.opener) {
// window.opener.announceWindow( window );
// }
}
// function announceWindow( win ) {
// window.close();
// }
<button onclick="windowOpen()" target=_blank>
Open Window
</button>
You could use something like this:
let google;
let open = false;
function toggleWindow() {
open = !open;
if (open) {
google = window.open("https://www.google.com/", "_blank", "width=400, height=450");
} else {
google.close();
}
}
You can do like this:
var Window = window.open('https://www.google.com');
function windowOpen() {
if(Window !== null){
alert("Window alreay open");
Window.close();
Window = null;
}else {
Window = window.open('https://www.google.com');
}
}
<button onclick="windowOpen()">
Open Window
</button>
open() function opens a new tab. It's name property has _blank value by default. But if you close the tab manually, then you have to refresh the page to work JS properly otherwise you will get alert "Window already open" even after the closing of the tab.
I want to open a new tab using JavaScript or jQuery.
I tried this code:
window.open("myurl", '_blank');
But browser gives me alert for pop-up blocked.
I have to open new tab without pop-up blocked alert.
Each and every client can't allow pop-up.
Can anyone help me please?
try this,
$('#myButton').click(function () {
var redirectWindow = window.open('http://google.com', '_blank');
redirectWindow.location;
});
working js fiddle for this http://jsfiddle.net/safeeronline/70kdacL4/2/
working js fiddle for ajax window open http://jsfiddle.net/safeeronline/70kdacL4/1/
The only way to overcome this is to perform a synchronous Ajax request which will block your browser while it runs, but will preserve the event context.
This will help--->
Open new tab without popup blocker after ajax call on user click
Here is the sample code for you --->
<table>
<tr>
<td>Works without warning in all browsers:</td>
<td><input type="button" onclick="performSyncronousRequest()" value="Syncronous request"/><td>
</tr>
</tr>
</table>
Scipt--->
/**
* This method will give open the popup without a warning.
*/
function performSyncronousRequest() {
$.ajax({
url: '/echo/html',
data: {},
success: function(){
window.open('http://www.w3schools.com');
},
async: false
});
}
Heres the working fiddle http://jsfiddle.net/23JNw/80/
var win = window.open('http://stackoverflow.com/', '_blank');
if(win){
//Browser has allowed it to be opened
win.focus();
}else{
//Broswer has blocked it
alert('Please allow popups for this site');
}
You can try like this
$(document).on('click', '.preview', function(event) {
event.preventDefault();
if (confirm("Are You Sure?"))
{
var daoGroup = $("#daoGroup").val();
if (daoGroup === undefined && daoGroup === null) {
alert("Select DAO Groups");
return false;
}
else
{
/* Act on the event */
var data = $(".frmContent").serialize();
var url = '<?php echo base_url() ?>reportViewPrint/sailorNominalRoll/htmlPreview';
window.open(url+'?'+ data, '_blank');
}
}
});
is there any way to detect that which popup window i have opened is closed or not?
<script type="text/javascript">
// global variable for subwindow reference
var newWindow;
// generate and fill the new window
function makeNewWindow() {
// make sure it isn't already opened
newWindow = window.open("http://www.google.com","sub","status,height=200,width=300");
}
function checkWindow() {
if(newWindow.closed){
document.write("Window has closed.");
}
}
</script>
<form>
<input type="button" value="Create New Window" onclick="makeNewWindow();" />
<script>
checkWindow();
</script>
</form>
I want that when i close the opened window. the function checkWindow() print on screen that "Window has closed." Please suggest me some helping code. thanks in advance
var win = window.open('http://www.google.com','google','width=800,height=600,status=0,toolbar=0');
var timer = setInterval(function() {
if(win.closed) {
clearInterval(timer);
alert('closed');
}
}, 1000);
The following is in the NewForm.aspx which gets executed from a parent page (surveys/lists/testsurvey/allitems.aspx). The javascript works and open google. However, it opens the google in the pop up window (newform.aspx) but i need to close the popup window and show google.com on the parent window (or whatever the parent window link is)
<script type="text/javascript">
function redirect()
{
var inputcCtrls = document.getElementsByTagName("input");
for(m=0; m<inputcCtrls.length; m++)
{
if(inputcCtrls[m].type == 'button' && inputcCtrls[m].value == 'Finish')
{
var funcOnClick = inputcCtrls[m].onclick;
inputcCtrls[m].onclick = function () { window.location = "http://www.google.com/" }; }
}
}
redirect();
</script>
Use the opener property to find the window that opened the current window:
window.opener.location = "http://www.google.com/";
window.close();