Playgrounds
Snippets
Developers
Compiler
All
ActionScript
Ajax
AngularJS
Apache
AppleScript
ASP.NET
Bash
C
C#
C++
Coffee
CoffeeScript
ColdFusion
Command
CSS
Delphi
Django
ES6
GLSL
Grunt
Gulp
HAML
Haskell
HTML
iOS
Jade
Java
JavaScript
jQuery
JSX
Less
LUA
MDX
MySQL
Objective
Other
Pascal
Perl
PHP
Plain text
PowerShell
Processing
Progress
Prolog
Pseudocode
Python
Rails
RegExr
Ruby
SASS
Scala
Scheme
SCSS
SmallBASIC
Smarty
SQL
Stylus
SVG
Swift
TypeScript
VHDL
X++
XHTML
XML
Xojo
XSLT
New snippet
New playground
Sign up
Login
Upload
Playgrounds
Snippets
Developers
Sign up
Login
Javascript window.location
JavaScript
by
Jamie Peak
3rd November 2011
<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"
0
Reply?
R
Ryan
8 years ago
Yo
0
Reply?
Chad Moore
6 years ago
<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>
0
Reply?
N
NO
1 year ago
Write a comment
Send 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.
3 Responses
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"
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.