closing a new browser tab using jquery / javascript - javascript

A new tab opens up when i click a link given in a iframe. Is it possible to close these newly opened tabs by giving some controls in the iframe

Most modern browsers sandbox each tab, preventing the ability to do what you're requesting. As an example, run this jsFiddle and watch your JS console in your browser.
The code will open a new browser tab using JS so we have a little bit of control over it:
var x = window.open('https://www.google.com');
But, when we try to close it:
x.close();
In most browsers you will see an error when you attempt to control navigation or close the window in the second (sandboxed) tab.

Related

Close the current tab and open new tab using javascript

Close the current tab and open a new tab using JavaScript. On Chrome or any other browser.
Try this:
window.open('http://www.google.com','_blank');
window.setTimeout(function(){this.close();},1000);
Close the current tab
You can't close the current tab until and unless it has parent
reference
Its simple, if the current tab is opened by self I mean, you went to browser and typed the url in the url bar can't be closed with the javascript. Because of security reasons browsers will not allow these type of things.
If you try the following code
window.close();
you'll get following warning message by browser
Scripts may close only the windows that were opened by it.
If the tab is opened with window.open, right click on the link and opened on anchor tag then following should work
window.close();
self.close();
Opening new tab using the javascript :
window.open("https://stackoverflow.com");

Single mouse click to open new tab + modal window at same time

See for example:
http://www.retailmenot.com/view/macys.com
When you click on one of the buttons, it both automatically opens a new tab, and pop out their modal window.
What are the possible ways to do this?
They seem to do both actions with Javascript. They actually do something that keeps the window in the current tab and not on the one that was opened. How is it done?
In general, Can I achieve these two actions (nevermind if focus is on new window) with a regular form submission with target=_blank the new tab, and some class to pop the modal window? What should the javascript look like?
Is there any way to do this without javascript at all?
Basically I'm looking for practices that are supported from IE8+, and cross browser compliant.
See this : http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_open
You can open your js modal also inside myFunction() function.

Open new tab in browser window (opened with window.open)

I have a new window opened via window.open method and in that window in content I have a link with "target=_blank".
When clicked the link opens new tab in parent window instead of the one that content was in. I also noticed that for that window (created with window.open) the Ctrl+T shortcut (to open blank tab, Firefox) does not work.
I checked window.open specs and I didn't find any option that would allow this behavior.
var a = window.open("http://www.google.pl",
"Test",
"width=640,height=480,scrollbars=yes,toolbar=yes,menubar=no,location=no,resizable=yes");
a.focus();
Setting toolbar=yes makes it work in Firefox. Any idea how to make it work in chrome?
Could you show some code?
else; try with javascript:
function OpenNew(){
window.open("http://www.google.se", "_blank");
}
Rgds

window.print in new window breaks hashchange in windows chrome

This may be a specific issue with Chrome that I should take to their forums, but I wanted to see if there was an alternate solution or a fix. We are using backbone.js for our single page app and to print, we create a new window, write our html to it and then call print on the new window. If a user closes the tab without closing the print dialog, the hashchange and popstate events do not fire anymore in the Backbone.History object. You can't refresh the page either. We have to close the page and reopen in a new tab to restart.
This error does not occur on linux builds, just windows. If the user closes the print dialog first and then the tab, everything works normally.
The ideal solution would be for the hashchanges to keep working. If this isn't possible, is there another solution to do a print of a certain portion of HTML?
I've tried writing a script that calls window.print() in the new window but it does not fire or even throw an error. IFrames will not work because the css of the single page app will overwrite the printing portions html. Any solutions are welcome.
Here is a jsfiddle to show you the problem.
http://jsfiddle.net/5P4qv/3/
window.document.getElementById('run_print').onclick = function () {
window.onhashchange = function () {
console.log('hashchanged');
};
window.location.hash = 'test';
windowObject = window.open("", "_blank");
windowObject.document.open();
windowObject.document.close();
windowObject.focus();
windowObject.print();
};
You may need to allow popups for this to work. Click the print button and the popup will open to the print dialog. Close the window without closing the print dialog and the original window will act as if it is still loading. You will not be able to refresh either.
Again, this is only on Chrome in windows.

JavaScript close tab after window.open()

I've got a page which open a new window fullscreen but it still has the other page (the one which re-directs) behind so when you close the new window you are taken back to a blank page.
Is there a way to open a new window and then close the tab which is now inactive?
Currently I have some javascript like this
window.open("http://website.co.uk");
Thanks
You can technically use window.close() on the opening tab, but browsers usually will not allow JavaScript to close windows that it has not opened. Can you redirect to some useful page that the user can use once they have closed the window?
If you can add some JavaScript code to the page being opened, I think you can use window.opener.close() to close the original window. I tested it in IE8, the browser will ask for confirm before close the original window.

Categories