In meinem Widget habe ich diesen Code:Rewrite-Code von jquery javascript
$(document).ready(function() {
$('a[rel!=ext]').click(function() { window.onbeforeunload = null; });
$('form').submit(function() { window.onbeforeunload = null; });
});
ich diesen Code in vielen Web-Seiten gesetzt haben. Mein Problem ist, dass nicht alle meine Webseiten jQuery ausführen, also brauche ich eine JavaScript-Lösung.
Wie sieht das in JavaScript-Code aus?
UPDATE:
function showWidget(www){
var content = '<iframe src="'+www+'" style="border:0px #FFFFFF none; position: fixed;left: 0px;width: 300px; height:100%; top: 30%;z-index: 9999999;" name="myiFrame" scrolling="yes" frameborder="0" marginheight="0px" marginwidth="0px" height="100%" width="100%"></iframe><a style="display:none;" href="http://bedbids.com" rel="ext">BedBids</a>';
var newNode = document.createElement("DIV");
newNode.innerHTML = content;
document.body.appendChild(newNode);
window.onbeforeunload = function() {
return "You're leaving the site.";
};
window.onload = function() {
[].slice.call(document.querySelectorAll('a[rel!="ext"]')).forEach(function(a) {
a.onclick = function() {
window.onbeforeunload = null;
};
});
[].slice.call(document.getElementsByTagName('form')).forEach(function(form) {
form.onsubmit = function() {
window.onbeforeunload = null;
};
});
};
}
Versuchen window.onload zu entfernen, wenn die Funktion ausgeführt wird, wenn DOM bereit ist. – jcubic
Ich entferne es, aber es ist keine Lösung – Andrew