开发者

Trigger a URL using JavaScript

开发者 https://www.devze.com 2023-02-19 02:37 出处:网络
I need a script that triggers a URL(go to the URL and that\'s it). What\'s the shortest way to开发者_高级运维 write this script?Use window.location.

I need a script that triggers a URL(go to the URL and that's it).

What's the shortest way to开发者_高级运维 write this script?


Use window.location.

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

Or shorter (not recommend though).

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

No ajaxical magic needed.


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

Of course you could code-golf out the url and the semicolon.


Thanks: Use window.location.

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


This is a sample AJAX code sample that can be used to fire a silent query to the browser and fetch the response and act 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

精彩评论

暂无评论...
验证码 换一张
取 消