如何在iframe内的另一个textarea中加载文本 [英] how to load the text in another textarea where the textarea is within iframe

查看:93
本文介绍了如何在iframe内的另一个textarea中加载文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码plz中,告诉我如何在textarea路径为parent.frame_name1.iframe_name1.form_name1.textarea_name1的textarea中加载文本

 <!DOCTYPE HTML PUBLIC-// W3C // DTD HTML 4.01 Transitional // EN 
http://www.w3.org/TR/html4/loose.dtd\"> ;
< html>
< head>
< meta http-equiv = Content-Language content = zh-cn>
< meta http-equiv = Content-Type content = text / html; charset = iso-8859-1>
< title>本地文件I / O< / title>
< script type = text / javascript>
<!-//开始
var ForReading = 1,
ForWriting = 2,
ForAppending = 8;
var objFSO = new ActiveXObject( Scripting.FileSystemObject);

函数checkText(fld,btn){
btn.disabled = false;
fld.onkeypress = null;
返回true;
}

函数checkFile(obj,div,btn,btn2,fld){
div.innerHTML ='< p>< b>< b> File:< / b> ;< b>大小:< / b>& nbsp;& nbsp;& nbsp;& nbsp;< b>最后修改:< b> / p>';
btn.disabled = true;
btn2.disabled = true;
fld.value =‘’;
fld.onkeypress = new Function( return checkText( + document。 + fld.form.name +。 + fld.name +, + document。 + btn2.form.name +。 + btn2.name +));
//
// if(obj.value.indexOf(:)!= 1){
// alert(本地文件名必须包含驱动器号。);
//返回false;
//}
var ary = obj.value.split( \\);
if(ary.length< 2){
alert(本地文件名必须包含路径。);
返回false;
}
if(!/(\.txt)$ / i.test(obj.value)){
alert(本地文件名必须包含'.txt'扩展名。 );
返回false;
}
//
试试{
objFile = objFSO.GetFile(obj.value);
} catch(e){
if(e.message!=未找到文件){
alert(e.message);
返回false;
}否则{
尝试{
if(confirm(obj.value + \n +不存在。单击'确定'创建它。)){
objFile = objFSO.CreateTextFile(obj.value);
objFile.Close();
objFile = objFSO.GetFile(obj.value);
} else {
返回false;
}
}捕获(e){
警报(e.message);
返回false;
}
}
}
fileSpecs(div,btn);
objFile = null;
返回true;
}

函数fileSpecs(div,btn){
if(objFile.Size> 0){
btn.disabled = false;
} else {
btn.disabled = true;
}
var str =’< p>’;
str + =’< b>文件:< / b> ’+ objFile.Path +’< br>’;
str + =’< b>大小:< / b> ’;
if(objFile.Size< 1024){
str + = objFile.Size +’bytes';
}否则{
str + =(objFile.Size / 1024).toFixed(1)+‘Kbytes’;
}
str + =’& nbsp;& nbsp;& nbsp;& nbsp;’;
str + =’< b>上次修改时间:< / b> ’+ objFile.DateLastModified;
str + =’< / p>’;
div.innerHTML = str;
}

函数loadFile(btn,obj,div,fld){
objFile = objFSO.GetFile(obj.value);
objStream = objFile.OpenAsTextStream(ForReading);
fld.value = objStream.ReadAll();
objStream.Close();
objStream = null;
fileSpecs(div,btn);
objFile = null;
返回true;
}

函数saveFile(btn,obj,div,fld,btn2){
btn.disabled = true;
objFile = objFSO.GetFile(obj.value);
objStream = objFile.OpenAsTextStream(ForWriting);
objStream.Write(fld.value);
objStream.Close();
objStream = null;
objFile = objFSO.GetFile(obj.value);
fileSpecs(div,btn2);
objFile = null;
fld.value =‘’;
fld.onkeypress = new Function( return checkText( + document。 + fld.form.name +。 + fld.name +, + document。 + btn.form.name +。 + btn.name +));
返回true;
}
//结束->
< / script>
< / head>

< body>
< center>
< form name = myForm onsubmit = return false;>
< table width = 720>
< tr>
< td colspan = 4>
< div id = fileSpec>
< b> b:文件:< / b> br< b>大小:< / b>& nbsp;& nbsp;& nbsp;& nbsp; < b>上次修改:< / b< / p>
< / div>
< / td>
< / tr>
< tr>
< td colspan = 3 width = 580 align = center valign = top>
< textarea rows = 25 name = fileArea cols = 70
onkeypress = return checkText(this,btnSave);>< / textarea> < / td>
< td rowspan = 2 width = 140 valign = top< p>这是基于浏览器的本地文本文件编辑器
的简单演示。首先点击< b>浏览< / b>
按钮可从本地硬盘驱动器中选择现有的文本文件。 
(如果需要
,则可以在浏览对话框中键入新的文件名。)然后,所选文件信息将显示在页面顶部
中。对于现有文件,请点击< b> Load< / b>
按钮。编辑后,点击< b>保存< / b> < / p>< / td>按钮。
< / tr>
< tr>
< td align = left>
< input type = file name = fileName size = 50
onchange = return checkFile(this,document.getElementById('fileSpec'),btnLoad,btnSave,fileArea); > < / td>
< td align = center>
< input type = button name = btnLoad value = Load已禁用
onclick = return loadFile(this,fileName,document.getElementById('fileSpec'),fileArea); > < / td>
< td align = center>
<输入类型=按钮 name = btnSave value =保存已禁用
onclick = return saveFile(this,fileName,document.getElementById('fileSpec'),fileArea,btnLoad) ;> < / td>
< / tr>
< / table>
< / form>
< / center>

< / body>
< / html>


解决方案

您是说要加载的文件名吗包含在 parent.frame_name1.iframe_name1.form_name1.textarea_name1 中?在这种情况下,您应该动态更改<输入类型= file /> 的值,该值不受浏览器的支持(这是一个安全问题)。 / p>

in the below code plz tell me how to load the text in textarea where the textarea path is parent.frame_name1.iframe_name1.form_name1.textarea_name1

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Local File I/O</title>
    <script type="text/javascript">
    <!-- // Begin
    var ForReading = 1,
        ForWriting = 2,
        ForAppending = 8;
    var objFSO = new ActiveXObject("Scripting.FileSystemObject");

    function checkText(fld, btn) {
        btn.disabled = false;
        fld.onkeypress = null;
        return true;
    }

    function checkFile(obj, div, btn, btn2, fld) {
        div.innerHTML = '<p><b>File:</b><br><b>Size:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Last Modified:</b></p>';
        btn.disabled = true;
        btn2.disabled = true;
        fld.value = '';
        fld.onkeypress = new Function("return checkText(" + "document." + fld.form.name + "." + fld.name + "," + "document." + btn2.form.name + "." + btn2.name + ")");
        //
        // if (obj.value.indexOf(":") != 1) {
        // alert("Local file name must include a drive letter.");
        // return false;
        // }
        var ary = obj.value.split("\\");
        if (ary.length < 2) {
            alert("Local file name must include a path.");
            return false;
        }
        if (!/(\.txt)$/i.test(obj.value)) {
            alert("Local file name must include the '.txt' extension.");
            return false;
        }
        //
        try {
            objFile = objFSO.GetFile(obj.value);
        } catch (e) {
            if (e.message != "File not found") {
                alert(e.message);
                return false;
            } else {
                try {
                    if (confirm(obj.value + "\n" + "does not exist. Click 'Ok' to create it.")) {
                        objFile = objFSO.CreateTextFile(obj.value);
                        objFile.Close();
                        objFile = objFSO.GetFile(obj.value);
                    } else {
                        return false;
                    }
                } catch (e) {
                    alert(e.message);
                    return false;
                }
            }
        }
        fileSpecs(div, btn);
        objFile = null;
        return true;
    }

    function fileSpecs(div, btn) {
        if (objFile.Size > 0) {
            btn.disabled = false;
        } else {
            btn.disabled = true;
        }
        var str = '<p>';
        str += '<b>File:</b> ' + objFile.Path + '<br>';
        str += '<b>Size:</b> ';
        if (objFile.Size < 1024) {
            str += objFile.Size + ' bytes';
        } else {
            str += (objFile.Size / 1024).toFixed(1) + ' Kbytes';
        }
        str += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
        str += '<b>Last Modified:</b> ' + objFile.DateLastModified;
        str += '</p>';
        div.innerHTML = str;
    }

    function loadFile(btn, obj, div, fld) {
        objFile = objFSO.GetFile(obj.value);
        objStream = objFile.OpenAsTextStream(ForReading);
        fld.value = objStream.ReadAll();
        objStream.Close();
        objStream = null;
        fileSpecs(div, btn);
        objFile = null;
        return true;
    }

    function saveFile(btn, obj, div, fld, btn2) {
        btn.disabled = true;
        objFile = objFSO.GetFile(obj.value);
        objStream = objFile.OpenAsTextStream(ForWriting);
        objStream.Write(fld.value);
        objStream.Close();
        objStream = null;
        objFile = objFSO.GetFile(obj.value);
        fileSpecs(div, btn2);
        objFile = null;
        fld.value = '';
        fld.onkeypress = new Function("return checkText(" + "document." + fld.form.name + "." + fld.name + "," + "document." + btn.form.name + "." + btn.name + ")");
        return true;
    }
    // End -->
    </script>
    </head>

    <body>
    <center>
    <form name="myForm" onsubmit="return false;">
    <table width="720">
    <tr>
    <td colspan="4">
    <div id="fileSpec">
    <p><b>File:</b><br><b>Size:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Last Modified:</b></p>
    </div>
    </td>
    </tr>
    <tr>
    <td colspan="3" width="580" align="center" valign="top">
    <textarea rows="25" name="fileArea" cols="70"
    onkeypress="return checkText(this, btnSave);"></textarea> </td>
    <td rowspan="2" width="140" valign="top"><p>This is a simple demonstration of
    a browser-based local text file editor.&nbsp; Begin by clicking the <b>Browse</b>
    button to select an existing text file from your local hard drive.&nbsp;
    (In the Browse dialog, you may type in a new file name if
    desired.)&nbsp; The selected file information is then displayed at the
    top of the page.&nbsp; For an existing file, click the <b>Load</b>
    button next.&nbsp; After editing, click the <b>Save</b> button to
    complete the demonstration.</p></td>
    </tr>
    <tr>
    <td align="left">
    <input type="file" name="fileName" size="50"
    onchange="return checkFile(this, document.getElementById('fileSpec'), btnLoad, btnSave, fileArea);"> </td>
    <td align="center">
    <input type="button" name="btnLoad" value="Load" disabled
    onclick="return loadFile(this, fileName, document.getElementById('fileSpec'), fileArea);"> </td>
    <td align="center">
    <input type="button" name="btnSave" value="Save" disabled
    onclick="return saveFile(this, fileName, document.getElementById('fileSpec'), fileArea, btnLoad);"> </td>
    </tr>
    </table>
    </form>
    </center>

    </body>
    </html>

解决方案

Are you meaning that the filename what you want to load is contained in parent.frame_name1.iframe_name1.form_name1.textarea_name1 ? In this case you should change the <input type="file"/> value dynamically, which is not supported by browsers (it would be a security issue).

这篇关于如何在iframe内的另一个textarea中加载文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆