Run url using javascript

I need a script that runs the url (go to the url and it).

What is the shortest way to write this script?

+4
source share
4 answers

This is an example of AJAX sample code that you can use to run a silent request into a browser and receive a response and actions on it.

var xmlhttp; if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest(); else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { // Do something with the result, like post a notification $('#notice').html('<p class="success">'+xmlhttp.responseText+'</p>'); } } xmlhttp.open('GET',url, true); xmlhttp.send(); 
0
source

Use window.location .

 window.location = 'http://stackoverflow.com'; 

Or shorter (not recommended, though).

 location = 'http://stackoverflow.com'; 

Ayaxial magic is not required.

+4
source
 window.location='http://www.google.com'; 

Of course, you could encode golf from a URL and a semicolon.

+2
source

Thanks: Use window.location.

window.location = ' /fooobar.com / ... ';

+1
source

Source: https://habr.com/ru/post/1344540/


All Articles