How do I make multiple tabs open in a new window? - javascript

I use this script to create a button which opens the 3 links in new tabs, but in the same window
<html><head>
<script type="text/javascript">
function open_win()
{
window.open("https://google.com/")
window.open("https://www.gmail.com/")
window.open("https://www.facebook.com/")
}
</script></head>
<body>
<form> <input type=button value="Start a Blog" onclick="open_win()"> </form>
</body> </html>
I found another code to open a link in new window of 300*250.
<a href="https://google.com/" onclick= "window.open('https://google.com/','newwindow','width=300,height=250');
return false;"> </a>
Now , I want to combine these two. I want a button as in the first case, to open a new window of 300*250 and then open the three links in new tabs in that window.

You can't. window.open can create two different kinds of windows, depending on whether certain options are specified in the third argument:
Normal browsing windows (which most modern browsers will open in tabs of the current window)
Popup windows (which cannot contain tabs)
There is no way to "mix and match" these two options.

Related

HTML JS Open new window with console in google chrome

This is client-side HTML. I'm just using HTML for automation.
My initial goal was to open a new window https://live.ipms247.com/login/ and then paste the values in the three login fields. All three fields have ID tags. And I can write to them from the console. For example.
document.getElementById("username").value="sample";
document.getElementById("hotelcode").value="12345";
document.getElementById("password").value="Password";
I wrote a code to copy text from parent window to child window at the click of a button.
My code is on a local file.
<html>
<head>
<script type="text/javascript">
function init()
{
popupWin = window.open('https://live.ipms247.com/login/','popupWin','');
}
function transferText()
{
popupText = popupWin.document.getElementById("username");
parentText = document.getElementById("parentTextBox");
popupText.value = parentText.value
}
</script>
</head>
<body>
<input type="text" id="parentTextBox" onkeyup="transferText();" value="Hello World">
<input type="button" onclick="init();" value="popup window">
<input type="button" onclick="transferText();" value="Transfer Text">
</body>
</html>
However, this does not work, apparently because my code is on a local file and the website is on another domain.
So my only solution to this problem, so far, is to launch the site with onlick and then focus to it. Press Ctrl+Shift+J to open the console and then paste the commands (I have code which copies them to clipboard) and hit enter.
Is there any possibility to launch the new window with the console open and focus on the console?
You can not do this because JavaScript restricts you to the user.
If you want to reach your goal, you can use the frames API

How to open multiple url-web-links via custom local .html?

Once upon a time I encountered a simple but efficent script that allows to paste copied links (line by line) into a box and then after pressing a button it opened all of the links (http://etc.etc) in a new tab.
Unfortunately I have deleted this gem.
Can you help me to make a simple local .html page where user could paste list of urls:
http://url.one
http://url.two
and after pressing a button it will open them url-s in a browser
thats what im looking for:
https://thewindowsclub-thewindowsclubco.netdna-ssl.com/wp-content/uploads/2014/07/urlopener.jpg
closest call is this;
<html>
<head>
<script type="text/javascript">
function open_win() {
window.open("http://www.java2s.com/")
window.open("http://www.java2s.com/")
}
</script>
</head>
<body>
<form>
<input type=button value="Open Windows" onclick="open_win()">
</form>
</body>
</html>
instead of predefined URL-s user should be able to paste own links in form of list
To open a new tab, you would use the javascript command window.open(url,'_blank');, where the URL is a reference to the URL you'd like to open. Here's a refrence for window.open.
For your specific usecase, you'd want to create a HTML document with something like a <textarea> in it, and a submit button. You'd then take the text, split it into an array along newlines, (using String.split), then loop over the result and call the window.open function on each entry.
I hoped this helped!
Here is how to do it
document.getElementById("submit").addEventListener("click", function(){
var urls = document.getElementById("url").value.split(" ");
console.clear();
urls.forEach(function(element){
console.log(element)
window.open(element,'_blank');
});
});
<p>Insert your URl seperated by space </p>
<input type="text" id="url" value="https://www.google.se http://www.icefilms.info/" />
<input type="button" id="submit" value="open" />

Window.open-ing to the same popup, even from multiple tabs

Here is a simple HTML:
<html>
<body>
<input type="button" value="open popup" onclick="window.open('http:\\www.example.com', 'popupName', 'width=100, height=100');">
</body>
</html>
so when you click on the button, a new popup will be created and no matter how many times you click it, that popup will be refreshed from now on.
Thats right. But if you opened my HTML in 2 tabulators? Then 2 popups will be opened, no matter if their names are the same. How to have actually one popup then?

check if a browser tab is already open so I don't make extra tabs

When a user adds an item to our shopping cart it opens our store in a new tab. Different websites oddly enough.
I would like to check if the tab is already open and then repopulate it it with the second item instead of opening another tab with the updated cart.
Is there a way to check this with js? I imagine I can track that we opened the tab but I don't see how I can confirm that it wasn't closed in the time between adding items to the cart without doing some ajax requests pinging both pages etc. Which seems like overkill.
So simply how do you check if a browser tab is already open?
Edited with a solution:
First:
var tab = window.open('http://google.com','MyTab');
Then:
if(tab) {
var tab = window.open('http://yahoo.com','MyTab');
}
window.open has the following parameters: var tab = window.open(url, name, specs, replace)
As long as you use the same name the url will be loaded into that window/tab.
If you wanted to keep the descriptor/reference (tab above), that window.open returns, once the user refreshes the page, that reference is lost.
I think your best bet could be session storage / local storage, but it works only in newer browsers.
All you need is to save a reference to the opened tab that you can relate with some id that will make sense to you... Then when you need to reopen it again just use the saved reference from there you can access your parent or opener window from window.opener. Also to know when the child window is closed there is a default browser event "beforeunload" that when called can remove the window from your reference object in your parent so you know that you have to reopen it not just focus it.
I gone through each steps and I came up with some points.
I tested it on IE.
It did not worked as expected if you use URL like (htp://www.google.com) and it worked if you use your domain page.
While it worked well for Firefox and chrome.
Following example does not work:
<script type="text/javascript">
function myfunction1() {
window.open('http://www.google.com', 'f');
}
function myfunction2() {
window.open('http://www.yahoo.com', 'f');
}
</script>
<body>
<form id="form2" runat="server">
<div>
<a href="#" onclick='myfunction1();'>myfunction1</a>
<a href="#" onclick='myfunction2();'>myfunction2</a>
</div>
</form>
</body>
</html>
And Following example works:
<script type="text/javascript">
function myfunction1() {
window.open('WebForm1.aspx', 'f');
}
function myfunction2() {
window.open('WebForm2.aspx', 'f');
}
</script>
<body>
<form id="form1" runat="server">
<div>
<a href="#" onclick='myfunction1();'>myfunction1</a>
<a href="#" onclick='myfunction2();'>myfunction2</a>
</div>
</form>
</body>
</html>

to open a page in new tab using self.location?

I am using self.location="www.google.com"; in my code to open google page. How can i open same page in another window.
You can use the window object's open method like so:
window.open("www.google.com");
You can use an <a> tag and set the target="_blank" property to open a page in anew tab/window. Whether this will be opened in a new tab/windows depends entirely on the settings in the user agent.
Google
try this
window.open ("www.google.com","mywindow");
<script>
function fullwin(targeturl) {
window.open(targeturl,"","fullscreen,scrollbars")
}
</script>
<form>
<input type="button" onClick="fullwin('mypage.html')" value="Show My Frameset">
</form>
i see at least one freaky method:
<a id='newwnd' href='goole.com' style='display:hidden' target='blank'></a>
...
document.getElementById('newwnd').click();

Categories