简体   繁体   English

使用JavaScript触发URL

[英]Trigger a URL using JavaScript

I need a script that triggers a URL(go to the URL and that's it). 我需要一个触发URL的脚本(转到URL就是这样)。

What's the shortest way to write this script? 编写此脚本的最短方法是什么?

Use window.location . 使用window.location

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

Or shorter (not recommend though). 或者更短(不推荐)。

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

No ajaxical magic needed. 不需要ajaxical魔法。

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

当然你可以编码 - 打高尔夫球和分号。

Thanks: Use window.location. 谢谢:使用window.location。

window.location = ' http://stackoverflow.com '; 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. 这是一个示例AJAX代码示例,可用于向浏览器发出静默查询并获取响应并对其执行操作。

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM