I am having trouble with window.open() in javascript. I have it set up in such a way that at the click of a button certain data will be validated on the server side in php. If the data is valid, then $openView is set to true. Once the page reloads, I have the function popUP() call onload. For some reason that is unknown to me, the window.open doesn't do anything
function popUp()
{
//if the view button was click with a valid input
<?php if ($openView){?>
window.open("view.php?resName=<?php echo $resumename;?>");
<?php }?>
}
I have tried it without the php statement, I have tried to echo window.open() from the server side. Nothing helped.The goal is to open the given page in a new window after the data has been validated on the server side. Any suggestions?
The problem
I am afraid that your browser does not allow such script to prevent popups .
The solution
You browser (and his popup blockers) will typically only allow window.open if used during the processing of a user event (like a click). So you should try to redesign your script behaviour.
Maybe another interesting approach
Maybe you should consider using a nice popup-like jquery plugin like Fancybox . This won't be blocked by your browser, since it's not a real popup.
You need to write the function in javascript as:
<script>
function popUp(resumename;)
{
window.open("view.php?resName="+resumename+"");
}
</script>
<a href="javascript:popUp(<?php echo $resumename ?>)">Test</a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.