views:

63

answers:

1

This code is in visualforce (salesforce's page editor language). Basically the apex:repeat tags function as a sort of loop, generating a set of urls from outputlink. All these urls have a class of "name".

What the jquery is to do is find all the urls with the class name, and click them so they open in new windows. Its not working.

<apex:page standardcontroller="Account" extensions="maininvoice">

<apex:repeat value="{!theListOfIDs}" var="anId">
     <apex:outputLink target="_blank" value="{!URLFOR($Page.invoice2,anId)}" styleClass="name" />
</apex:repeat>

<apex:includeScript value="{!URLFOR($Resource.jquery, 'js/jquery-1.4.2.min.js')}"/>
<script type="text/javascript">
var j$ = jQuery.noConflict();
j$(document).ready(function(){

$('.name').click();
alert("debug");
                }
                );

</script>

</apex:page>
+1  A: 

A .click() won't cause the default behavior to occur (e.g. following the link/opening a window), if you want that to happen, you'll have to call window.open() yourself, like this:

var j$ = jQuery.noConflict();
j$(function(){
  $('.name').each(function() {
    window.open(this.href);
  });
  alert("debug");
});

Note though, most browsers will block you from doing this, not sure what to recommend there, and I'd personally dislike opening windows on page load as well.

Nick Craver
Right thanks for the reply but thats not even working. Is there anything else you can suggest perhaps a workaround
Sean
Nicks code does work, see example here http://jsbin.com/adome/edit
Daveo
Strangely this exact code does not work in salesforce.
Sean
It will work with "j$('.name').each(function()" - note the "j" in the front. A minor typo. I've tested it in Salesforce but I won't post code in answer as the reputation should go to Nick :)
eyescream