Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery open url in popup window with height + weight and pass a param to it

Im trying to load on the click of a div a url but in a new window with certain sizes. For example I would have

<div id="mydiv>
   Roy
  click on this div
</div>

and

<div id="mydiv>
   Alex
  click on this div
</div>

Then the idea is a new window will popup ( not a modal ) with say sizes like 300x400px. The username should be passed to this window and I want to be able to do something with it in my web application. Jquery just needs to call something like /chatwindow/?user=rob

What would be a good way to approach this?

like image 638
Rubytastic Avatar asked Dec 11 '25 13:12

Rubytastic


2 Answers

Ok, try this

<div id="mydiv-alex" class="mydiv">
    Alex click on this div
</div>
<div id="mydiv-jonh" class="mydiv">
    Jonh click on this div
</div>
<script>
    $('.mydiv').click(function(){
    window.open(' /chatwindow/?user='+$(this).attr('id').replace('mydiv-',''), '_blank', 'width=300,height=400');
    return false;
    });
</script>
like image 131
feralou Avatar answered Dec 13 '25 03:12

feralou


try this

<div id="mydiv">
   Alex
  click on this div
</div>



 <script type="text/javascript">
        var windowSizeArray = [ "width=200,height=200",
                                "width=300,height=400,scrollbars=yes" ];

        $(document).ready(function(){
            $('#mydiv').click(function (event){

                var url ="www.yourdomain.com/chatwindow/?user=rob";
                var windowName = "popUp";//$(this).attr("name");
                var windowSize = windowSizeArray[ $(this).attr("rel") ];

                window.open(url, windowName, windowSize);

                event.preventDefault();

            });
        });
    </script>
like image 37
COLD TOLD Avatar answered Dec 13 '25 01:12

COLD TOLD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!