Trying to open a Link in a Pop-up Window

Trying to open a Link in a Pop-up Window

HaroldPeetHaroldPeet Posts: 8Questions: 2Answers: 0
edited February 2023 in Free community support

I am trying to build an internal website.

I am trying to open a pop-up window by clicking a link on a Filed in the row of the table, the link will retreive furhter information based on the infomration passed in the url.. Works fine opening in another tab but I can't seem to find away to open in a POP-UP.

This Works fine and Opens in a New Tab

columns: [
    {"data": "itemid",
    "render": function ( data, type, row, cellData ) {
        return '<a target="_blank" href="./forms/frm_ContractPrice.php?sku=' + row.itemid + '"> ' + data + '</a>';
    }},

Trying to open the URL in a Pop-up whcich uses window.open it doesn't work.

columns: [
    {"data": "itemid",
    "render": function ( data, type, row, cellData ) {
        return '<a href="#" onclick="pop_up(./forms/frm_ContractPrice.php?sku=' + row.itemid + ')"> ' + data + '</a>';
        }},

This is the pop_up Function.

function pop_up(url) {
    window.open(url, 'win2', 'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=1076,height=768,directories=no,location=no')
}

I am able to Add a button pointing to a form that opens fine in a Pop_up window.

buttons: [
    { text: 'Open Form',
        action: function (e, dt, button, config) {
            pop_up('./forms/frm_ContractPrice.php');
        }}
]

Hoping someone can tell me what I am doing wrong.

Thanks Harold

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    Trying to open the URL in a Pop-up whcich uses window.open it doesn't work.

    When you say it doesn't work, do you mean it opens in a new tab, rather than a new window?

    If so, you aren't doing anything wrong. This is 100% a browser thing. You can't control, in Javascript, if the browser will do window.open in a new tab or a new window. It is a browser configuration option that the user will set (or more likely just use the browser default). For example in the Firefox settings I see:

    Chrome will have something similar.

    Allan

  • HaroldPeetHaroldPeet Posts: 8Questions: 2Answers: 0

    Thanks Allan

    To clarify when I try to use window.open in the href link it does Nothing, mouse over the link shows that it wants to reload current page with # added to the end.

    From the button the window.open works as expected.

    I have been using the window.open with php tables and Foreach loops and they work so don't think the browser is limiting. I am hoping to be able to move to the datatables editor but I do use the pop_up frequenly to present addition information to users.

    <td><a href="#" onclick="pop_up('./forms/frmorderdisplay.php?OrderNumber=<?php echo $order['OrderNumber'] ?>')"> <?php echo $order['OrderNumber'] ?></td>

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    edited February 2023 Answer ✓

    Do you get errors in the browser's console when clicking the link?

    I think you have a syntax error. I believe you need to put quotes around the parameter you are sending to the popup function. Something like this:

        "render": function ( data, type, row, cellData ) {
            return '<a href="#" onclick="pop_up(&quot;./forms/frm_ContractPrice.php?sku=' + row.itemid + '&quot;)"> ' + data + '</a>';
         }
    

    Notice the two HTML quotes (&quot;) I added.

    Kevin

  • HaroldPeetHaroldPeet Posts: 8Questions: 2Answers: 0

    Thanks Kevin

    I tried adding the Quotes as you suggested but same result nothing appears to happen, other than mouse ove show the current url, I didn't see anything in the Browser Console under Network Fetch/XHR or JS.

    Also tried single quote but then I get squiggly red lines as errors.

    {"data": "description",
        "render": function ( data, type, row, cellData ) {
         return '<a href="#" onclick="pop_up("./forms/frm_ContractPrice.php?sku=' + row.row.itemid + '")"> ' + data + '</a>';}
                    }, 
    
  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    Answer ✓

    Also tried single quote but then I get squiggly red lines as errors.

    Yes, I would think that will result in a syntax error due to where the open and close quotes line up.

    The code snippet I provided seems to work here:
    http://live.datatables.net/niwuxita/1/edit

    Do you get errors in the browser's console when clicking the button?

    Can you provide a link to your page or a test case replicating the issue so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • HaroldPeetHaroldPeet Posts: 8Questions: 2Answers: 0

    Thank you so much Kevin

    That worked great. As you indicated proper syntax was my original problem and using the " instead of " was the key.

    Harold

  • HaroldPeetHaroldPeet Posts: 8Questions: 2Answers: 0

    Sorry I shoud have previewed before posting it translated the quotes see below.

    onclick="pop_up(&quot;./forms/frm_ContractPrice.php?sku=    -   Works
    onclick="pop_up("./forms/frm_ContractPrice.php?sku=         -   Does not work
    
Sign In or Register to comment.