Html 通过单击图像调用函数
我找到了一个将弹出窗口置于屏幕中央的功能:Html 通过单击图像调用函数,html,image,function,onclick,popup,Html,Image,Function,Onclick,Popup,我找到了一个将弹出窗口置于屏幕中央的功能: function PopupCenter(url, title, w, h) { // Fixes dual-screen position Most browsers Firefox var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : window.screenX; var
function PopupCenter(url, title, w, h) {
// Fixes dual-screen position Most browsers Firefox
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : window.screenX;
var dualScreenTop = window.screenTop != undefined ? window.screenTop : window.screenY;
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
var left = ((width / 2) - (w / 2)) + dualScreenLeft;
var top = ((height / 2) - (h / 2)) + dualScreenTop;
var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
// Puts focus on the newWindow
if (window.focus) {
newWindow.focus();
}
}
但当我试图通过按下图像来调用它时,什么都没有发生,我甚至没有得到一个klick me鼠标
<img src="https://rainbowcats.se/img/btn-makeown.gif" height ="auto" width ="80%"alt="Skapa din egen minnessida" onclick= "PopupCenter('https://upload.rainbowcats.se','xtf','900','500');">
该功能加载在头部,另一个加载在身体中
有人有什么建议吗?我为自己感到羞耻 我忘了最重要的一件事,我忘了在JavaScript中设置函数
<script type="text/javascript">
(Function)
</Script>
有时最容易忘记的事情是..您使用过外部js吗?这些代码应该可以工作。也许在html代码中函数的实现中有错误。您确定您的函数在所有测试中都被调用了吗?顺便说一下,要显示click me鼠标,请添加style=cursor:pointer使用hit F12并读取所有错误。这些代码都在HTML页面中,奇怪的是页面开始显示第一个代码,即函数。。