在PHP中调用Javascript-Window.open
我试图调用php文件中的window.open()javascript代码,但不幸的是它没有响应 这是我的密码:在PHP中调用Javascript-Window.open,php,javascript,Php,Javascript,我试图调用php文件中的window.open()javascript代码,但不幸的是它没有响应 这是我的密码: <html> <head> <script language="JavaScript"></script> </head> <body> <?php ..... $printHeader .= " <div id ='subHeader'><p class = 'alignleft'&
<html>
<head>
<script language="JavaScript"></script>
</head>
<body>
<?php .....
$printHeader .= " <div id ='subHeader'><p class = 'alignleft'><font style='color:blue'>User: " . $username . " | Access: " . $level ." | <a href=logout.php>Logout</a></font></p>";
$printHeader .= " <p class='alignright'><a href='refresh.php' onClick='window.open(this.href,'mywin','width=400,height=200')'>Refresh List</a></p></div>";
$printHeader .= "<div style='clear: both;'></div>";
.... ?>
</body> </html>
我认为问题与引号有关,您的内部单引号将结束onClick字符串,因此将外部单引号替换为双引号(将保持内部引号为单引号)将解决您的问题。尝试更改此选项:
onClick='window.open(this.href,'mywin','width=400,height=200)'
为此:
onClick=\"window.open(this.href,'mywin','width=400,height=200)\"
下面是一个例子:
另一种解决方案是通过在内部引号前面加反斜杠(\
)来转义引号。我马上注意到的一件事是,您没有使用onclick
事件转义单引号。修改如下:
onclick=\"window.open(this.href, 'mywin', width=400, height=200);\"
看看这是否有帮助。您希望发生什么?javascript控制台会说什么?它是否显示任何错误?您使用的浏览器是什么?您的PHP是否包含echo$printHeader
任何位置?呈现的HTML是什么样子?onClick
!=onclick
在所有浏览器中:确保从PHP双引号onclick=\“window.open(…)\”
@SetSailMedia中转义onclick双引号。不管怎样,我编辑它。