1

Currently I am using an click element to open a popup box to share some content on the social network

The code i used is :

$('#qq').attr("onclick", "window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=" + encodeURIComponent(location.href) + "&title=" + encodeURIComponent(shareDes) + "&pics=" + imgStr + "', 'QQshare','toolbar=0,status=0,width=800,height=500');");

Which generate a box , and in that box there is an textarea

<textarea class="view_summary"  id="summary" ><%=escHTML(summary)%></textarea>

How to clear the element inside it? I simply add $('.view_summary').empty(); after the create box code, which does not work. Thanks

user1871516
  • 979
  • 6
  • 14
  • 26
  • 1
    Try $('.view_summary').val('') – Lim H. Jun 18 '13 at 02:33
  • .empty() should work on textarea too. Can you replicate in a fiddle.? Here is one http://jsfiddle.net/jnPHr/ – PSL Jun 18 '13 at 02:34
  • Thanks for answering but it is not working . Because it is not in the same page but in a pop up box? I tried $('.view_summary').is('*') return false and $('.view_summary').val() return undefined, thanks – user1871516 Jun 18 '13 at 02:38
  • Is the window using the same domain as the page with creates the window? – Arun P Johny Jun 18 '13 at 02:44

2 Answers2

2

If the new window has the same domain as the page opening it then try

$('#qq').on("click", function(){
    var win = window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=" + encodeURIComponent(location.href) + "&title=" + encodeURIComponent(shareDes) + "&pics=" + imgStr + "', 'QQshare','toolbar=0,status=0,width=800,height=500');
    win.onload = function(){
        $('#summary', win.document).val('');
    }
});

Demo: Plunker

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
0

i'm not sure on this, but you might want to try $('#summary').empty();

mayorbyrne
  • 495
  • 1
  • 5
  • 16
  • Thanks for answering but it is not working . Because it is not in the same page but in a pop up box? I tried $('#summary').is('*') return false and $('#summary').val() return undefined, thanks – user1871516 Jun 18 '13 at 02:38
  • http://stackoverflow.com/questions/6017796/jquery-select-element-in-parent-window the second part of the selected answer looks to be what you need – mayorbyrne Jun 18 '13 at 02:43