function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
dreamrealdreamreal 

Why doesn't this simple page with javascript work in salesforce?

I am trying to create a page that will open several links in new windows. I've tried several methods which dont work and am now  beginning to think that salesforce does not allow the opening of new pages. For example:

 

 

<apex:page standardcontroller="Account" extensions="maininvoice">
 <body>
  <p id="hello">Hello World</p>
  <a href="http://www.google.com" class="name">google</a>
  <a href="http://www.yahoo.com" class="name">yahoo</a>
</body>

    <apex:includeScript value="{!URLFOR($Resource.jquery, 'js/jquery-1.4.2.min.js')}"/>
<script type="text/javascript">

var j$ = jQuery.noConflict();
j$(function(){
  $('.name').each(function() {
    window.open(this.href);
  });
});
 
</script>

</apex:page>

does not work in salesforce but if I do it outside of salesforce it does: http://jsbin.com/adome/edit

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Chris JohnChris John

Try replacing the script section to this, worked for me:

 

<script type="text/javascript">

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

</script>

All Answers

Chris JohnChris John

Try replacing the script section to this, worked for me:

 

<script type="text/javascript">

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

</script>

This was selected as the best answer
splitsplit
<apex:includeScript value="{!URLFOR($Resource.jquery, 'js/jquery-1.3.2.min.js')}"/>


<script type="text/javascript">
var j$ = jQuery.noConflict();
j$(function(){
  j$('.name').each(function() {
    window.open(this.href);
  });
});
</script>

 

=)

Chris JohnChris John

That will also work :)