Travis build: 1020
This commit is contained in:
10
README.md
10
README.md
@ -2012,15 +2012,19 @@ Redirects the page to HTTPS if its currently in HTTP. Also, pressing the back bu
|
||||
|
||||
Use `location.protocol` to get the protocol currently being used. If it's not HTTPS, use `location.replace()` to replace the existing page with the HTTPS version of the page. Use `location.href` to get the full address, split it with `String.split()` and remove the protocol part of the URL.
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
const httpsRedirect = () => {
|
||||
if (location.protocol !== 'https:') location.replace('https://' + location.href.split('//')[1]);
|
||||
};
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
httpsRedirect(); // If you are on http://mydomain.com, you are redirected to https://mydomain.com
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
@ -381,6 +381,7 @@ console<span class="token punctuation">.</span><span class="token function">log<
|
||||
</pre><button class="primary clipboard-copy"><img src="clipboard.svg" alt="clipboard"> Copy to clipboard</button></div></div><div class="card fluid"><h3 id="httpsredirect" class="section double-padded">httpsRedirect</h3><div class="section double-padded"><p>Redirects the page to HTTPS if its currently in HTTP. Also, pressing the back button doesn't take it back to the HTTP page as its replaced in the history.</p><p>Use <code>location.protocol</code> to get the protocol currently being used. If it's not HTTPS, use <code>location.replace()</code> to replace the existing page with the HTTPS version of the page. Use <code>location.href</code> to get the full address, split it with <code>String.split()</code> and remove the protocol part of the URL.</p><pre class="language-js"><span class="token keyword">const</span> <span class="token function-variable function">httpsRedirect</span> <span class="token operator">=</span> <span class="token punctuation">()</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
|
||||
<span class="token keyword">if</span> <span class="token punctuation">(</span>location<span class="token punctuation">.</span>protocol <span class="token operator">!==</span> <span class="token string">'https:'</span><span class="token punctuation">)</span> location<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token string">'https://'</span> <span class="token operator">+</span> location<span class="token punctuation">.</span>href<span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">'//'</span><span class="token punctuation">)[</span><span class="token number">1</span><span class="token punctuation">]);
|
||||
};</span>
|
||||
</pre><label class="collapse">Show examples</label><pre class="language-js"><span class="token function">httpsRedirect</span><span class="token punctuation">();</span> <span class="token comment">// If you are on http://mydomain.com, you are redirected to https://mydomain.com</span>
|
||||
</pre><button class="primary clipboard-copy"><img src="clipboard.svg" alt="clipboard"> Copy to clipboard</button></div></div><div class="card fluid"><h3 id="onuserinputchange" class="section double-padded">onUserInputChange</h3><div class="section double-padded"><p>Run the callback whenever the user input type changes (<code>mouse</code> or <code>touch</code>). Useful for enabling/disabling code depending on the input device. This process is dynamic and works with hybrid devices (e.g. touchscreen laptops).</p><p>Use two event listeners. Assume <code>mouse</code> input initially and bind a <code>touchstart</code> event listener to the document. On <code>touchstart</code>, add a <code>mousemove</code> event listener to listen for two consecutive <code>mousemove</code> events firing within 20ms, using <code>performance.now()</code>. Run the callback with the input type as an argument in either of these situations.</p><pre class="language-js"><span class="token keyword">const</span> <span class="token function-variable function">onUserInputChange</span> <span class="token operator">=</span> callback <span class="token operator">=></span> <span class="token punctuation">{</span>
|
||||
<span class="token keyword">let</span> type <span class="token operator">=</span> <span class="token string">'mouse'</span><span class="token punctuation">,</span>
|
||||
lastTime <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
|
||||
|
||||
Reference in New Issue
Block a user