使用Javascript将字符串写入文本文件

时间:2015-07-30 13:02:04

标签: javascript html text-files activexobject

我们正在尝试将存储在字符串中的网址保存到文本文件中,但我们似乎无法将其工作。它不会保存到文件中,尽管我们的测试显示该函数实际上正在运行。

此处的代码如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>

<button onclick="instagramclick()">Login to instagram</button>
<button onclick="myFunction()">Test Button</button>

<script>

function myFunction() {
    alert("Hello World");
}

function instagramclick(){
    alert("button clicked");
    window.location.href = "https://instagram.com/oauth/authorize/?client_id=8a612cd650344523808233c0468c80ed&redirect_uri=http://u-ahmed.github.io/HookedUp/instagram.html&response_type=token";
}

function WriteDemo(link)
{
 var fso, f, r;
 var ForReading = 1, ForWriting = 2;
 fso = new ActiveXObject("Scripting.FileSystemObject");
 f = fso.OpenTextFile("database.txt", ForWriting, true);
 f.Write(link);
 f.Close();
 r = f.ReadLine();
return(r);
}

window.onload = function writedamnyou(){
var token = window.location.href.substring(62);
if (token != ""){
    // document.write(token);
    var link = "https://api.instagram.com/v1/users/self/feed?access_token=" + token;
    // w = window.open('database.txt')
    WriteDemo(link);
  // document.write(stuff);


}
};

</script>
<p id="no"></p>
</body>
</html>

提前致谢。

0 个答案:

没有答案
相关问题