Hallo zusammen,
ich bin neu im Javascript Bereich und habe eine Funktion gefunden, um Popups zu erstellen.
Außerdem habe ich die Variable popupStatus = 0 deklariert. Ein Popup öffnet sich aber nicht.
So sah mein Test aus:
openpop("Test","Test",1);
Kann mir da jemand helfen?
Gruß
ich bin neu im Javascript Bereich und habe eine Funktion gefunden, um Popups zu erstellen.
Code:
function openpop(titel,text,ishtml) { $("#popupContact > h1").html(titel); if(ishtml) $("#contactArea").html(text); else $("#contactArea").text(text); $("img","#contactArea").attr({src:"",alt:"Bild"} ); centerPopup(); loadPopup(); $("#contactArea").find("textarea").focus().keypr es s(function (e) { if (e.which == 13 && !e.shiftKey) { $("#contactArea").find('input[type="submit"]').click(); } }); } function initpop() { GM_addStyle("#backgroundPopup{ \ display:none; \ position:fixed; \ _position:absolute; \ height:500%; \ width:500%; \ top:-15px; \ left:-15px; \ background:#000000; \ border:1px solid #cecece; \ z-index:298; \ } \ #popupContact{ \ display:none; \ position:fixed; \ min-width:40%; \ max-width:80%; \ max-height:80%; \ background:#FFFFFF; \ border:2px solid #cecece; \ z-index:299; \ padding:12px; \ font-size:13px; \ } \ #popupContact h1{ \ text-align:left; \ color:#6FA5FD; \ font-size:22px; \ font-weight:700; \ border-bottom:1px dotted #D3D3D3; \ padding-bottom:2px; \ margin-bottom:20px; \ } \ #popupContactClose{ \ font-size:14px; \ line-height:14px; \ right:6px; \ top:4px; \ position:absolute; \ color:#6fa5fd; \ font-weight:700; \ display:block; \ } \ "); $("body").before(''+ '<div id="popupContact"> '+ ' <a id="popupContactClose">x</a> '+ ' <h1></h1> '+ ' <p id="contactArea"> '+ ' </p> '+ '</div> '+ '<div id="backgroundPopup"></div>'); $("#popupContactClose").click(function() { disablePopup(); }); $("#backgroundPopup").click(function() { disablePopup(); }); $(document).keypress(function(e) { if(e.keyCode==27 && popupStatus==1) { disablePopup(); } }); } function loadPopup() { if(popupStatus==0) { $("#backgroundPopup").css({ "opacity": "0.7" }); $("#backgroundPopup").fadeIn("fast"); $("#popupContact").fadeIn("fast"); popupStatus = 1; } } function disablePopup(){ if(popupStatus==1){ $("#backgroundPopup").fadeOut("fast"); $("#popupContact").fadeOut("fast"); popupStatus = 0; } } function centerPopup(){ var windowWidth = document.documentElement.clientWidth; var windowHeight = document.documentElement.clientHeight; var popupHeight = $("#popupContact").height(); var popupWidth = $("#popupContact").width(); //centering $("#popupContact").css({ "position": "fixed", "top": windowHeight/2-popupHeight/2, "left": windowWidth/2-popupWidth/2 }); }
So sah mein Test aus:
openpop("Test","Test",1);
Kann mir da jemand helfen?
Gruß
Kommentar