仅从javascript将网页输出为文本

output web page as text only from javascript

本文关键字:文本 输出 网页 javascript 仅从      更新时间:2023-09-26

我有一个使用母版页的ASP.NET页面。在此基础上,我有一个脚本,我想做的是重写HTML的输出,只给我一个没有所有HTML标题等的街道名称。

这是剧本,你能告诉我怎么做吗?

    function getAddress(Latitude, Longitude) {
        var geocoder = new google.maps.Geocoder();
        var Lat = parseFloat(Latitude);
        var Lng = parseFloat(Longitude);
        var latlng = new google.maps.LatLng(Lat, Lng);
        geocoder.geocode({ 'latLng': latlng }, function (results, status) {
            if (status === google.maps.GeocoderStatus.OK) {
                // document.clear();
                document.open();
                document.write(results[0].formatted_address);
                document.close();
            }
            else {
                // Do nothing
                document.open();
                document.write('');
                document.close();
            }
            geocoder = null;
        });
    }

我不必使用母版页(在我发布这个问题后,我可能会尝试不使用它)。

我知道document.write被认为是不好的做法,但上面只是我尝试做的一个例子

我将使用HTTP请求等从我的VB.NET应用程序调用此页面,所以我只想返回一个带有街道名称的纯文本文件。

使用ASP.NET加载页面时,不会执行javascript。此外,您不能用javascript更改页面的类型。

您可能会找到另一个解决方案,一个更好的解决方案:-)