Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Is it possible to include script and meta tags before the the standard salesforce tags?

The standard head is like the following:

<head>
<script src="/jslibrary/1351189248000/sfdc/JiffyStubs.js"></script>
<style type="text/css"></style>
<script src="/jslibrary/1351189248000/sfdc/SfdcCore.js" type="text/javascript">
</script><script src="/static/111811/js/picklist.js" type="text/javascript"></script>
<script src="/jslibrary/1351189248000/sfdc/VFState.js" type="text/javascript"></script>

Now first my modifications follow:

<link class="user" href="/resource/16456546546/Foo/css/main.css" rel="stylesheet" type="text/css">

<meta http-equiv="PRAGMA" content="NO-CACHE">
<meta http-equiv="Expires" content="Mon, 01 Jan 1990 12:00:00 GMT">
<meta content="IE=EmulateIE8" http-equiv="X-UA-Compatible">
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<script src="/resource/1354808845000/SCRM/script/jquery.min.js" type="text/javascript"></script> <script src="/resource/1354546456/Foo/script/jquery-ui.min.js" type="text/javascript"></script>

 <title>Site Login</title> </head>

I need to be able to insert something before the first Salesforce standard script tag. E.g. according to http://boards.developerforce.com/t5/Visualforce-Development/Struggling-with-IE/td-p/506213.

share|improve this question
    
Try wrapping your code in a {} code comment, since it's not visible here. –  Adam Dec 13 '12 at 17:16
add comment

3 Answers 3

Using the <apex:includeScript /> and <apex:stylesheet /> tags instruct the VF parser to place the contents into the rendered document <head> block. It does not matter where these tags are physically placed in the VF (or component) markup, the result will be a script or stylesheet reference within the <head> block at a known location.

Scripts are normally injected into the markup just after SfdcCore.js and the stylesheet is injected just after the SalesForce 'theme' stylesheet definition.

Unfortunately, this same feature of conveniently rendering items into the head doesn't exist for <meta> tags within the document using an apex tag. If you define the meta tags within the body, you're creating invalid markup per the spec, though most browsers tolerate this without complaint.

Scripts which have been included using the <apex:includeScript /> tag more than one time in the VF markup will not include multiple references to the script in the rendered markup. I presume this uniqueness aspect exists in the <apex:stylesheet /> tag as well.

As a side-note, be aware that adding <html> and <head> and <title> tags directly in your VF markup may result in stray tags in the rendered document (multiple html or head tags, etc). This would also be considered invalid markup.

Depending on what your requirement is to 'insert something before the first Salesforce standard script tag', you can use JavaScript to insert elements before it in the DOM like so:

var js = document.createElement('script');
js.src = 'myscript.js';
var first = document.getElementsByTagName('script')[0];
first.parentNode.insertBefore(js, first);
share|improve this answer
add comment

To prevent invalid markup through having multiple head tags, and to be able to inject content into the head tags of a visualforce page I suggest you look at the apex:page attribute of applyhtmlTag. If you set this to false, you can manually define the head tags yourself and add whatever you need between them.

This also allows you to add meta tags at build time rather than after the page is loaded.

share|improve this answer
add comment

if you are referring to VisualForce pages, I have had to do this quite a few times. I usually keep all such tags just after the <Apex:page> tag.

Something like:

<apex:page sidebar="false" showheader="false" standardstylesheets="false">
<apex:includeScript value="{!URLFOR(................)}" />
<apex:stylesheet value="{!URLFOR(...................')}" />

<html>

    <head>
         <link>...</link>
         <title>Customer Portal Home</title>

         <style>
         </style>
        </head>

       <body>
       </body>
</html
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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