注册 登录
编程论坛 WEB前端(UI)

想用一个本地html文件中的一个按钮获得远程地址中的内容,尝试了httpRequest和frames都不行,貌似遇到了同源问题,请大侠帮忙。

wanguhssheng 发布于 2018-08-22 10:41, 2643 次点击
如网址:http://www.
1 回复
#2
wanguhssheng2018-08-22 11:02
<!DOCTYPE HTML>
<html>
    <head>
        <title>指定网址,获得内容</title>
        <link rel = "stylesheet" type = "text/css" href = "mystyle.css"></link>
        <style>
            #pannel{
                color:red;
            }
        </style>
    <head>
    <body>
        <script>
            var httpRequest = new XMLHttpRequest();
            function getfromnet(){
                var url = document.getElementById("theurl").value;
                alert(url);
                //var httpRequest = new XMLHttpRequest();
                httpRequest.onreadystatechange = handleResponse;
                httpRequest.open("GET", url);
                httpRequest.send();
                sleep(1000);
            }

            function handleResponse(){
                alert("here");
                alert(httpRequest.responseText);
            }

        </script>
        <div id = pannel style="border: medium maroon dashed;width:31em;">
            <p style="font-size:2rem"><h3>请输入目标网址:</h3></p>
            <input type = "textarea" placeholder = "http://10.0.4.87:8080/tisco/login.html#reloaded"
            id = theurl  
            value = "http://10.0.4.87:8080/tisco/login.html#reloaded"
            style = "text-decoration:underline;background:yellow;color:red;padding:2px;width:30em">
            </input>
            <p/>
            <input type = "submit" onclick = "getfromnet()"></input>
        </div>
        <a  href = "http://oa.(page)/tisconew">OA</a>
    </body>
</html>
1