• 締切済み

IE6 JavaScript download

使用しているIE6です。 ある画面には検索ボタンがありますが、検索を行ってから、取得したデータをcsvファイルとしてダウンロードします。ダウンロードする前に、ファイル保存をポップアップが必要です。 実現方法については まずlinkを動きで創建します。 var link = document.createElement("a"); linkの属性を設定します。 link.href = "data:text/csv;charset=utf-8," + "\ufeff" + encodeURIComponent(data); link.download = "aaa.txt"; IE6のほうは、fireEventを使います。 var evt = document.createEventObject(); link.fireEvent('onclick',evt) 質問:しかし、fireEventを呼び出すとき、「未定義エラー」となります。 ここで、困ってますので、教えてくれば、助かります。

みんなの回答

  • fujillin
  • ベストアンサー率61% (1594/2576)
回答No.1

文章の読解力に乏しいので、ご質問文の内容をあまり理解できてませんが… 勝手な想像で、以下のような感じで動作しませんか?  ・リンクをクリック → 通常のイベントが発生 → アラート表示  ・ボタンをクリック → fireeventでイベントを発生 → アラート表示 (一応I、E6.0で動作を確認) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html lang="ja"> <head><title>sample</title> <meta http-equiv="Content-Script-Type" content="text/javascript"> </head> <body> <p id="trriger"><input type="button" value="Event Fire!"> <script type="text/javascript"> //要素を生成 var link = (function(){  var link = document.createElement("a");  var p = document.createElement("p");  link.appendChild(document.createTextNode("Created Text"));  link.href = "#";  p.appendChild(link);  document.getElementsByTagName("body")[0].appendChild(p);  return link; })(); //イベントを設定 link.attachEvent('onclick', function(e){  alert("Link is clicked!"); }, false); document.getElementById("trriger").attachEvent('onclick', function(e){  var evt = document.createEventObject();  evt.button = 1;  link.fireEvent ("onclick", evt); }, false); </script> </body> </html>

risenliu
質問者

お礼

お礼が遅れてしまって、申し訳ございません。 ご回答ありがとうございました。 やっぱり、IE6のほう、サーバではファイルを作成しなければ、リンクのクリックイベントをトリガーしてもうまく動かれない。解決策として、IE&だったら、データをローカルのファイルに書き込みとなります。

関連するQ&A

  • canvas.onclick結果はどうやって受取?

    ■前提 canvas.onclick = function (evt) { //処理 //console.log(data); ■やりたいこと ・ここで「document.write(data);」すると画面が切り替わってしまうので、dataをreturnした上で改めて「document.write」したい ■困っていること ・「return data;」してからこの関数の外で「document.write」すると「Uncaught ReferenceError: data is not defined」となります ■知りたいこと ・canvas.onclick処理結果は、どうやって受け取るのでしょうか? var result = canvas.onclick = function (evt) { ?

  • appendChildがieだとできない??

    こんにちは。DOMについては全く無知です。 このようなのを作ったところ、google chromeでは動いたものの、ieでは動きませんでした。 var iBody = $("hoge").contentWindow.document.getElementsByTagName("body")[0]; var newText = document.createElement("div"); newText.innerHTML = "aaa"; iBody.appendChild(newText); ※$("hoge")は、iframeタグを指しています いろいろ試したところ、ieだとフレーム内にアクセスすることができないみたいです。 どうすればいいのか、ご存知でしたらご教示願います。

  • JavaScriptを使ってXMLにタグを打ち込みたいんですが。。

    プログラミング初心者で申し訳ありません。 JavaScriptを使っているのですが、ボタンを押して、<math>~</math>の中に数式のタグを入力しようとしています。 現状のソースですが、 ファイル名:sample.xhtml ~ <math id="math" xmlns="http://www.w3.org/1998/Math/MathML"> #数式のタグの入力位置 </math> <script type="text/javascript"> function mul1(){ var info = document.getElementById("math"); var txt1 = document.createTextNode("<mi>"); var txt2 = document.createTextNode("x"); var txt3 = document.createTextNode("</mi>"); info.appendChild(txt1); info.appendChild(txt2); info.appendChild(txt3); } </script> <form> <input type = "button" value="x" onclick ="mul1()" /> </form> ~ となっています。 理想は <math id="math" xmlns="http://www.w3.org/1998/Math/MathML">  <mi>x</mi> </math> ボタンクリック後こういう感じでタグを挿入したいと考えています。 function mul1(){ var info = document.getElementById("math"); var element1 = document.createElement("mi"); var element2 = document.createElement("/mi"); var txt = document.createTextNode("x"); info.appendChild(element1); info.appendChild(txt); info.appendChild(element2); } 要素追加と思いcreateElement()で検証してみたんですが、結果はなにも表示されませんでした。 言葉不十分で申し訳ありませんが、解決法教えていただけませんか? よろしくお願いいたします。

  • 下の様にjavaScriptでボタンを追加したいのですが、

    下の様にjavaScriptでボタンを追加したいのですが、 onclickイベントがHTMLにかかれません。 どうすればよろしいでしょうか。 よろしくお願いします。 var ele = document.createElement('input'); ele.type = 'button'; ele.value = 'ご意見へ'; ele.name = 'fNext'; ele.onclick = "sendRequest('FE0041')"; objct[0].parentNode.appendChild(ele);

  • javascript でリンクを動的に変更する方法

    下記のようなシステムを作成をしようと思っています。 javascript がまだあまり理解していない為ご教授いただければ幸いです。 質問としては追加ボタンで動的に追加した際に検索部分のリンクも一緒に動的に追加したいと考えています。 下記のリンクの「この部分」にも追加するごとにiの値が入るようにしたいと考えています。 <a href="#" onClick="window.open('store1.php?from=js&amp;no=「この部分」','search_store1','width=540,height=540')">検索</a> 宜しくお願い致します。 サンプルコード <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script language="JavaScript"> <!-- var i = 1; var maxrows = 10; function hage() { i++; // Tbody への参照を取得します var mybody=document.getElementById("histTablebody"); mystore_row=document.createElement("TR"); mystore_row.setAttribute("id","histrow"+i); mystore_cell=document.createElement("TD"); mystore_cell.setAttribute("id","num"); currenttext=document.createTextNode(i); mystore_cell.appendChild(currenttext); mystore_row.appendChild(mystore_cell); mystore_cell=document.createElement("TD"); currenttext=document.createTextNode("店舗ID"); mystore_cell.appendChild(currenttext); mystore_row.appendChild(mystore_cell); mystore_cell=document.createElement("TD"); mystore_form.setAttribute("type","TEXT"); mystore_form.setAttribute("name","store_id" + i); mystore_form.setAttribute("value",""); mystore_form.setAttribute("id", "storecell"); mystore_cell.appendChild(mystore_form); mystore_form=document.createElement("INPUT"); mystore_form.setAttribute("type","TEXT"); mystore_form.setAttribute("name","store_name" + i); mystore_form.setAttribute("value",""); mystore_form.setAttribute("id", "storecell"); mystore_cell.appendChild(mystore_form); mystore_row.appendChild(mystore_cell); mystore_cell=document.createElement("TD"); //mystore_cell=document.createElement("a"); mystore_row.appendChild(mystore_cell); mybody.appendChild(mystore_row); document.register.delrow.disabled=false; if(i>=maxrows){ document.register.addrow.disabled=true; } } var hige = function() { var mytable=document.getElementById("histTablebody"); var removeTable=document.getElementById("histrow"+i); mytable.removeChild(removeTable); i--; if(i==1){ document.register.delrow.disabled=true; } // 追加ボタンを有効にする document.register.addrow.disabled=false; } var result = function() { alert(''); } //--> </script> </head> <body> <form name="register"> <div id="hist"> <table border="1"> <tbody id="histTablebody"> <tr id="histrow1"> <td id="num">1</td> <td>店舗ID</td> <td><input type="text" name="store_id1" id="storecell"><input type="text" name="store_name1" id="storecell"></td> <td> [<a href="#" onClick="window.open('store1.php?from=js&amp;no=[]','search_store1','width=540,height=540')">検索</a>] </td> </tr> </tbody> </table> </div> <table> <tr> <td> <input type="button" id=addrow value="行を追加" onClick="hage();"> </td> <td> <input type="button" id=delrow value="行を削除" onClick="hige();" disabled="true"> </td> <td> <input type="button" value="登録" onClick="result()"> </td> </tr> </table> </form> </body> </html>

  • IEでF12を押さないとjavascriptが…

    javascript初心者です。 サイトのログインページに、 IDとpasswordを保存する機能をを作りたいと考えています。 プログラムからjavaccriptを呼び出しているのですが、 IEからそのjavascriptが読み込まれなくなってしまいました。 (Chrome,FireFox,Operaでは正しく動作しています。) F12を押してIEの開発者ツールを立ち上げると、正しく動作するようになります。 なぜ、F12を押さないと呼ばれないのかが、 さっぱりわからず、教えていただけないでしょうか。 htmlソースにも記述されています。 呼び出し元は、tclです。 <script language="JavaScript"> var rwAuthInfo = { conf : { kwordId : 'auth_id', kwordPass : 'auth_pass', savePeriod : 120, idElemKey : 'authId', passElemKey : 'authPass', chkElemKey : 'authSave' }, CookieWrite : function(kword, kdata, kday) { if (!navigator.cookieEnabled) { return; } var sday = new Date(); sday.setTime(sday.getTime() + (kday * 1000 * 60 * 60 * 24)); var s2day = sday.toGMTString(); document.cookie = kword + "=" + escape(encodeURIComponent(kdata)) + ";expires=" + s2day + ";path=/"; }, CookieRead : function(kword) { if (typeof(kword) == "undefined") { return ""; } kword = kword + "="; var kdata = ""; var scookie = document.cookie + ";"; var start = scookie.indexOf(kword); if (start != -1) { end = scookie.indexOf(";", start); kdata = decodeURIComponent(unescape(scookie.substring(start + kword.length, end))); } return kdata; }, getAuthInfo : function() { console.log("get auth info"); var myPass = decodeURIComponent(unescape(rwAuthInfo.CookieRead(rwAuthInfo.conf.kwordPass))); var obj1 = document.getElementsByTagName('input'); for(i = 0; i < obj1.length; i++){ if ( obj1[i].id == rwAuthInfo.conf.passElemKey && myPass != "" ) { obj1[i].value = myPass; } } var myId = rwAuthInfo.CookieRead(rwAuthInfo.conf.kwordId); var obj2 = document.getElementsByTagName('input'); for(i = 0; i < obj2.length; i++){ if ( obj2[i].id == rwAuthInfo.conf.idElemKey && myId != "" ) { obj2[i].value = myId; } } console.log("From cookie - id: " + myId + ", password: " + myPass); }, saveAuthInfo : function() { console.log("save authentication info"); var objChk = document.getElementById(rwAuthInfo.conf.chkElemKey); if ( objChk.type == "checkbox" && objChk.checked ) { var obj1 = document.getElementById(rwAuthInfo.conf.passElemKey); if ( obj1.value != null && obj1.value != '' ) { var myPass = escape(encodeURIComponent(obj1.value)); console.log("password: " + obj1.value + ", encoded: " + myPass); rwAuthInfo.CookieWrite(rwAuthInfo.conf.kwordPass, myPass, rwAuthInfo.conf.savePeriod); } var obj2 = document.getElementById(rwAuthInfo.conf.idElemKey); if ( obj2.value != null && obj2.value != '' ) { var myId = escape(encodeURIComponent(obj2.value)); rwAuthInfo.CookieWrite(rwAuthInfo.conf.kwordId, myId, rwAuthInfo.conf.savePeriod); } } }, addSubmitEvent : function() { for ( i=0; i<document.forms.length; i++ ) { var frm = document.forms[i]; try { frm.addEventListener('submit', rwAuthInfo.saveAuthInfo, false); } catch (e) { frm.attachEvent('onsubmit', rwAuthInfo.saveAuthInfo); } } }, addLoadEvent : function() { try { if (window.addEventListener) { window.addEventListener('load', rwAuthInfo.getAuthInfo, false); window.addEventListener('load', rwAuthInfo.addSubmitEvent, false); } else if (window.attachEvent) { var isMSIE = /*@cc_on!@*/0; if (isMSIE) { window.attachEvent('onload', rwAuthInfo.getAuthInfo); window.attachEvent('onload', rwAuthInfo.addSubmitEvent); window.attachEvent('load', rwAuthInfo.getAuthInfo); window.attachEvent('load', rwAuthInfo.addSubmitEvent); } else { window.attachEvent('onload', rwAuthInfo.getAuthInfo); window.attachEvent('onload', rwAuthInfo.addSubmitEvent); } } } catch (e) { console.error("got error in addLoadEvent: " + e); window.attachEvent('onload', rwAuthInfo.getAuthInfo); window.attachEvent('onload', rwAuthInfo.addSubmitEvent); } } } rwAuthInfo.addLoadEvent(); </script>

  • 外部javascriptファイルをjavascriptから動的に呼び出したい

    呼び出し元のURLによって動作を変えたいJAVASCRIPTがあります。 普段外部のJAVASCRIPTを呼び出すときはよくこうするのですが <script type="text/javascript" src="js.php?key=url"></script> これでは「key=url」が固定になってしまいます。そこで下記のように <script> var commentname=document.URL; var str=encodeURIComponent(commentname); document.write('<script type="text/javascript" src="read.php?key=',str,'"><\/script>'); </script> document.writeを使って無理やり外部Javascriptファイルの呼び出しスクリプトを書いているのですが、この書き方はどうもエレガントさにかけるというか、いまいち気に入りません。 もっとほかに良い方法がある気がするのですが、調べてもわかりませんでした。おわかりになる方がいらっしゃったらご教示頂けないでしょうか。

  • select option value が IE だけで動かない

    select の option 項目を追加する javascript を組んでいるのですが IE だけ項目追加ができません。Windows の Firefox2、Safari は期待 通りに項目が追加できました。 option.value を指定しないと IE でも追加できます。IE 専用に特別な 別プログラムが必要なのでしょうか。ご存知の方よろしくお願いします。 var selectBox = document.getElementById("select1"); var option = document.createElement('option'); option.setAttribute('value','my_value'); option.appendChild(document.createTextNode('my_text')); selectBox.appendChild(option); 3行目をコメントアウトすれば IE でも select にデータが追加され ますが、肝心の value がないのでプログラム的にダメなんです。

  • 記述方法について

    よろしくお願いします。前回こちらで教えて頂いたソースを 基に表示するテーブルの並び方を変えたいと思っています。 理想の並び方は、例として くま さる           くま  さる ごりら  これらを→ごりら うま  うま           りす りす というように読み込んだエクセルのレコードを2列ずつにして表したいのですが、可能でしょうか? 以下のソースを基に、色々試したのですが、ブラウザ上には何も出てきません。 -------------------------------------------------------------- <html> <head> <title>TEST CSV IN</title> <script type="text/javascript"> function hoge(){ var TEST = document.getElementById("TEST"); var output = document.getElementById("OUTPUT"); var table = document.createElement("table"); table.setAttribute("border","1"); table.setAttribute("datasrc","#TEST"); var tbody = document.createElement("tbody"); var trs = new Array(); var tds = new Array(); TEST.Reset(); var rs = TEST.recordset; while (!rs.EOF){ var tbl = document.createElement("table"); table.setAttribute("border","1"); var td = document.createElement("td"); for(var i=1; i<2; i++){   var tr = document.createElement("tr");   trs[0] = document.createElement("tr");   trs[1] = document.createElement("tr");   trs[2] = document.createElement("tr"); tds[0] = document.createElement("td"); tds[1] = document.createElement("td"); tds[2] = document.createElement("td"); var img = document.createElement("img"); img.setAttribute("src",rs.fields(0)); img.setAttribute("alt",""); tds[0].appendChild(img); tds[1].innerText = rs.fields(1); tds[2].innerText = rs.fields(2); trs[0].appendChild(tds[0]); trs[1].appendChild(tds[1]); trs[2].appendChild(tds[2]); tr.appendChild(trs[0]); tr.appendChild(trs[1]); tr.appendChild(trs[2]); tbody.appendChild(tr); } rs.MoveNext; } table.appendChild(tbody); output.appendChild(table); } </script> </head> <body onload="hoge();"> CSV DATA IMPORT Ver MINO <p> <object id="TEST" classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83"> <param name="DataURL" value="cn.csv" /> <param name="UseHeader" value="true" /> <param name="TextQualifier" value="'"> <param name="FieldDelim" value=","> </object> <div id="OUTPUT"> </div> </body> </html> ------------------------------------------------------------- javascriptを始めたばかりなので、まだよく理解していないので 大変申し訳ありませんが、ご指導願えればと思います。 よろしくお願いします。

  • CSVをIEで開かないようにするには?

    最初に環境を書いておきます。 OSはWindows 7 Home Premium 64bit Officeは2007 IEは8.0 上記の環境で、CSVファイルについてなのですが、 インターネット上からCSVファイルを閲覧しようとした際に、「ダウンロードか開くか」の選択肢が出ます。 ダウンロードは普通の動作なのですが、「開く」をすると、IEの中で開いてしまいます。 これをExcelの中で開かせるためにはどうすればよいのでしょうか? いろいろ検索もしてみてレジストリも変えてみたのですが、変化なしです…。 ご教示のほど、どうぞよろしくお願いします。