Open Window behind main window

Asked

Viewed 166 times

-1

I have this code that he does almost that. The only problem is that I the user needs to click on a link so that the main window gets in front. I want you to automatically open the Window behind the main window.

This is the code that opens the Window.

<script type="text/javascript">

$(document).ready(function () {
    window.name = "parent";
    $('#link').click(function (event){ 
        event.preventDefault();
        window.open('filho.php', 'fullscreen=yes', 'scrollbars=auto');
    });
});
</script>



<body>
        <a id="link" href="/">Open Window </a>
</body>

This is the code that goes back to page by clicking on the link.

<script type="text/javascript">//<![CDATA[
    $(document).ready(function () {

        $('#link').click(function(event){
            event.preventDefault();
            console.log(window.opener.location);
            var goBack = window.open('', 'parent');
            goBack.focus();

    });
    });//]]> 

    </script>


    <body>

        <a id="link" href="#">Return to Parent </a>

    </body>

CODE LINK WORKING: http://pontodosjogos.com/testegrana.php

  • 1

    ever thought of using Modals for that? is aesthetically better and more usual, link if you are interested: http://getbootstrap.com/javascript/#modals

  • My case I needed to open the contents in a window. @Bia

2 answers

1


Unfortunately what you intend is not possible. IE allows you to do this, but other browsers (Chrome and Firefox, for example) block this type of action without direct action by the user (such as clicking the link).

0

how are you using jquery ... utilize jquery-ui, very easy to implement Example jquery-ui Docs

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Dialog - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
    $( "#dialog" ).dialog();
  });
  </script>
</head>
<body>

<div id="dialog" title="Basic dialog">
  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>


</body>
</html>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.