URL Always open in new Window

How I strictly force to my website always open in a new single window without statusbar,menubar,toolbar, scrollbar .
whenever user if try to copy paste in address bar of browser first code will check this URL is opened in single window or not, if not it will auto open.

overall , How I allow my url always open in single wimdow amd prevent open in tab or direct browser address bar.

Immediate response is “why do you need that to be the case?”

The only way you’d be able to force this really is to always launch a subwindow when your URL is visited, but that may fall afoul of popup blockers.

I want to do this because I want when my URL will open , users not will do next work in next tab. Generally i seen this in my bank internet banking when I do successful login it opens in new single wimdow as I told in thread.

Yeah, your bank’s website is most likely calling window.open

Yes, I know this method, but how I detect user open my URL in window.open() or not? if not then it will auto move to window.open().

Hi there HermiomeGranger,

perhaps this example…

<!DOCTYPE HTML>
<html lang="en">
<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1">

<title>untitled document</title>

<link rel="stylesheet" href="screen.css" media="screen">

<style media="screen">
body {
    background-color: #f9f9f9;
    font: normal 1em / 1.5em BlinkMacSystemFont, -apple-system, 'Segoe UI', roboto, helvetica, arial, sans-serif;
 }
a {
    display: inline-block;
    padding: 0.5em 1em;
    border: 1px solid #999;
    border-radius: 0.5em;
    box-shadow: 0.25em 0.25em 0.25em rgba( 0, 0, 0, 0.4 );
    background-image: linear-gradient( to bottom, #fff, #ccc );
    color:  #333;
    text-decoration: none;
 }
</style>

</head>
<body> 

 <a id="a1" href="https://www.sitepoint.com/community/t/url-always-open-in-new-window/338984">Hermione Granger</a>

<script>
(function( w,  d ) {
   'use strict';
   var mywindow, features = 'menubar=0, status=0, toolbar=0, width=648, height=320, left=20, top=150';
   d.getElementById( 'a1' ).addEventListener( 'click', 
      function(e) {
         e.preventDefault();
         if ( mywindow ) {
              mywindow.close();
          }
         mywindow = w.open( this.href, 'spare-window', features );
         mywindow.focus();
      }, false );
}( window, document ));
</script>

</body>
</html>

…will help the cause. :winky:

coothead

1 Like

if window.history.length is 1, then you can assume the window was opened freshly to load the link.
Note that this doesnt necessarily mean they used your window.open method to open the page, just that its a fresh page.

thank you for writting code but @coothead I want without button function. I want if user try to access my website by simply paste url in address bar then it will auto move to window.open. I want prevent my website open in tab.

You can’t do this.

Simply put, you cannot detect tabs - that would be a violation of privacy nightmare.

2 Likes

Oh! I see. My plan flopped :smile:

HermioneGranger,

you have absolutely no control of the users browser.

coothead

3 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.