-2

does anybody knows how I can close a _blank-tab.

I have a custom button in my ribbon bar, which should send the URL of each selected list items (not just one).

Now, the problem is that I couldn't close the _blank-tab which I have opened while the E-Mail-Program is open.

Here my embedded code in the xml CommandAction:

javascript:function sendingURL() {
var ctx = SP.ClientContext.get_current();
var items= SP.ListOperation.Selection.getSelectedItems(ctx);
var url = '';
var wnd; 

for (var i in items)
{
    url += document.getElementById(items[i].id).getElementsByTagName('a')[0].href + '\n';
    wnd = window.open('mailto:?subject=blablabla&body=' + encodeURIComponent('Sending this URL:' + url));
    setTimeout(function() {
        wnd.close();
    }, 3000);
  }
}sendingURL();"

I did try something like this: reference

But I will get:

"script5007 unable to get value of the property 'close' object is null or undefined"

closed as off-topic by Eric Alexander Jun 30 '15 at 17:14

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions not specific to SharePoint are off-topic here, but can be asked on Stack Overflow." – Eric Alexander
If this question can be reworded to fit the rules in the help center, please edit the question.

  • This is a basic JavaScript question, not a SharePoint question, which probably explains the downvote. – wjervis Jun 30 '15 at 16:15
1

Because you do it for each item. For each item you assing the created window to the variable wnd. So at the end, wnd is the last opened window. However, for each item you want to close wnd after 3 seconds. that works for the first time, but then wnd is already closed.

You would have to assign a unique variable for each item (or do it in the item´s scope)

  • What´s the reason why you open the mailto-link in a new tab? – Leopold Lerch Jun 30 '15 at 10:53
1

I think we can use Closure to fix the problem.

javascript:function sendingURL() {
var ctx = SP.ClientContext.get_current();
var items= SP.ListOperation.Selection.getSelectedItems(ctx);
var url = '';
var wnd; 

for (var i in items)
{
    url += document.getElementById(items[i].id).getElementsByTagName('a')[0].href + '\n';
    wnd = window.open('mailto:?subject=blablabla&body=' + encodeURIComponent('Sending this URL:' + url));
               WaitNClose(wnd);
}
function WaitNClose(oWin){
   setTimeout(function() {   oWin.close(); }, 3000);
}

I haven't tested it but it should work.

  • 1
    should work too, however, there is still a Problem with the "url" variable, which is getting longer and longer in each Iteration and will produce a working URL only for the first Iteration. both variables (wnd and url) are in the wrong scope – Leopold Lerch Jun 30 '15 at 11:14
  • Thank you but ,this does not work... only one url will be displayed if I selected more than one – ryo hatake Jun 30 '15 at 11:38
  • As Leopold is saying, change the URL variable scope. It will work. – Vikram Shityalkar Jun 30 '15 at 13:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.