Javascript window.location

<script type="text/javascript"> <!-- window.location = "http://www.example.com/"; //--> </script>

3 Responses

Perhaps this changed since 2011:

window.location.host
"codepad.co"
window.location.hostname
"codepad.co"
window.location.href
" https://codepad.co/snippet/b4798e"
window.location.origin
" https://codepad.co"
window.location.pathname
"/snippet/b4798e"

Also:
document.URL
" https://codepad.co/snippet/b4798e"
Yo
<script>
class LimitedTextarea extends HTMLElement {
constructor(){
super();
this.attachShadow({mode:'open'});
this.maxLenght = this.getAttribute('max-length') || 200;
this.shadowRoot.innerHTML = `
<style>

</style>
<textarea></textarea>
<span id="counter"></span>
`;
this.textarea = this.shadowRoot.querySelector('textarea');
this.counter = this.shadowRoot.querySelector('#counter');
this.updateCoounter();
}
connectedCallback() {
this.textarea.addEventListener('input',()=>this.updateCoounter());
}
updateCoounter() {
const remaining = this.maxLenght - this.textarea.value.length;
this.counter.textContent = `${remaining} characters remaining`;
this.counter.style.color = remaining < 10? 'red' : 'black';
}
}
customElements.define('limited-textarea', LimitedTextarea);
</script>

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.