michelc Blog

Just <strong>another</strong> WordPress.com weblog

Archiver dans la catégorie ‘javascript

object.innerText for IE and FF

sans commentaires

Un système pour émuler la propriété innerText sous Firefox :

function getInnerText(elt) {
var _innerText = elt.innerText;
if (_innerText == undefined) {
_innerText = elt.innerHTML.replace(/<[^>]+>/g,"");
}
return _innerText;
}

Il suffit ensuite de remplacer :

var text = elt.innerText;

par :

var text = getInnerText(elt);

(publié à l’origine sur http://www.bigbold.com/snippets/posts/show/514)

En pratique, la propriété textContent a le même effet que innerText pour Firefox.

Rédigé par michel

27 juillet 2005 à 4:21

Publié dans Code Snippets, javascript

Fermer la fenêtre du navigateur

sans commentaires

Cette méthode fonctionne avec Internet Explorer (testé avec IE6) et Firefox (testé avec FF 1.5)

<input type="button" value="Close" onclick="CloseWindow();" />
<script type='text/javascript'>
<!--
function CloseWindow() {
	ww = window.open(window.location, "_self");
	ww.close();
}
-->
</script>

(publié à l’origine sur http://www.bigbold.com/snippets/posts/show/267)

Rédigé par michel

10 mai 2005 à 4:11

Publié dans Code Snippets, javascript

Confirmer la sortie d’un formulaire

sans commentaires

Cette méthode fonctionne avec Internet Explorer (testé avec IE6) et Firefox (testé avec FF 1.5)

window.onbeforeunload = function (evt) {
var message = 'Are you sure you want to leave?';
if (typeof evt == 'undefined') {
evt = window.event;
}
if (evt) {
evt.returnValue = message;
}
return message;
}

(publié à l’origine sur http://www.bigbold.com/snippets/posts/show/142)

Rédigé par michel

11 avril 2005 à 1:07

Publié dans Code Snippets, javascript