简体   繁体   English

<a>在php中回显的</a> html <a>标签中</a>执行javascript popup

[英]executing javascript popup in html <a> tag that are echo-ed in php

the flow is: a php page calls an ajax function that displays a list of user in a table without refreshing the pages. 流程是:php页面调用ajax函数,该函数在不刷新页面的情况下在表中显示用户列表。 in this table, i put a delete and edit link. 在此表中,我放置了一个删除和编辑链接。 I have no problem with the delete link however, i'm stuck at the edit link. 我的删除链接没有问题,但是我被卡在了编辑链接上。

what I'm trying to do is, when a user click edit link, there will appear a popup window, there, they can update the details of the user, but it appears that my popup window is not appearing. 我想做的是,当用户单击“编辑”链接时,将出现一个弹出窗口,在那里他们可以更新用户的详细信息,但似乎没有出现我的弹出窗口。

the javascript function is: javascript函数是:

<script type="text/javascript">
function newWindow(url) { 
var x,y;
x = screen.width-35;
y = screen.height-30;
var win =       window.open(url,'glossaryWindow','toolbar=no,directories=no,width=500,height=500'+
        'screenX=0,screenY=0,top=0,left=0,location=no,status=no,scrollbars=no,resize=yes,menubar=no');
    }

i put the function at the top of the page. 我将功能放在页面顶部。

this is the php code to call java function in html tag 这是在html标记中调用Java函数的php代码

echo "<td>" . '<a href="javascript: newWindow("/test/HTMLPages/popup_update_user.html")">edit</a>' . "</td>";

is it possible?? 可能吗??

i checked it its my URL that wrong, but that is not the problem. 我检查了它我的URL错了,但这不是问题。 the popup does not appear at all. 弹出窗口根本不会出现。 i need advise on this matter. 我需要在这件事上提供建议。

UPDATE: 更新:

this is the correct code for calling javascript in tag within php: 这是在php中的标记中调用javascript的正确代码:

 <?php
    echo "<td>" . "<a href=\"#\" onclick=\"newWindow('popup_update_user.html')\">edit</a>". "</td>"; ?>

:D :d

The problem is that in the echo you are opening and closing the statement before calling the javascript function. 问题在于,在echo中,您在调用javascript函数之前正在打开和关闭语句。

And don't call the function in the "href", call it from "onclick". 并且不要在“ href”中调用该函数,而应从“ onclick”中调用它。

Try this: 尝试这个:

echo "<td> <a href=\"#\" onclick=\"newWindow('/test/HTMLPages/popup_update_user.html')\">edit</a></td>";

EDIT: Working example 编辑:工作示例

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
            function newWindow(url) { 
            var x,y;
            x = screen.width-35;
            y = screen.height-30;
            var win =       window.open(url,'glossaryWindow','toolbar=no,directories=no,width=500,height=500'+
                    'screenX=0,screenY=0,top=0,left=0,location=no,status=no,scrollbars=no,resize=yes,menubar=no');
                }
    </script>
    </head>
    <body>
        <table>
            <tr>
                <?php
                echo "<td> <a href=\"#\" onclick=\"newWindow('/test/HTMLPages/popup_update_user.html')\">edit</a></td>";
                ?>
            </tr>
        </table>
    </body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM