1

I have a code that opens a new window with specific height and width. I would prefer, if possible, to open a new tab instead of a new window, but still being able to specify the height and width of the new tab. Is that possible?

<html>
<head>
</head>
<body>
<input type="button" onclick='var myW=window.open

("http://www.google.com/", "mywindow", "width = " + window.screen.width + ", height = " + window.screen.width / 3 + "");'>
</body>
</html>
fernando
  • 89
  • 1
  • 15
  • 1
    How can you resize new tab? The tab takes full height and width of the window. – Praneet Dixit Dec 13 '20 at 14:23
  • I think you have a point, to make the tab the size I want, I guess i would have to start making the first window that size. If so, would the following tabs would have the same size as the parent window? – fernando Dec 14 '20 at 02:22
  • I think that you can do one thing - Open the link in new tab (in the existing window) and then resize the existing window. – Praneet Dixit Dec 14 '20 at 03:07
  • yes, I think that should work too, thank you. – fernando Dec 14 '20 at 03:23

2 Answers2

1

As I know it is not possible to decide if a new link is opened only in tab. The settings of the browser decide if a new clicked link target="_blank" is opend in a tab or window. for sure its possible to force with javascript to open a new window and not tab.

Existing Questions:

about forcing open in a new Tab: HTML: how to force links to open in a new tab, not new window

Resize windows with Javascript: https://www.w3schools.com/jsref/met_win_resizeto.asp

cnm
  • 61
  • 6
1

you can replace myWindow.resizeTo(250, 250); number to change window size

<p>Open a new window, and resize the width and height to 500px:</p>
<button onclick="openWin()">Create window</button>
<button onclick="resizeWin()">Resize window</button>

<script>
var myWindow;
function openWin() {
  myWindow = window.open("", "", "width=100, height=100");
}
function resizeWin() {
  myWindow.resizeTo(250, 250);
  myWindow.focus();
}
</script>
masoud Goodarzi
  • 72
  • 1
  • 1
  • 6
  • You are right, thank you, but it is not what I'm looking for. When the new window is created, it has the right size already, my issue is that I would prefer to open a new tab because some browsers block the pop ups and a new tab is more friendly – fernando Dec 13 '20 at 13:45