Using Javascript to replace rendered HTML

If you want to replace HTML in a rendered page client side, you may wish to use something like the code below. It is particularly useful in a management system where it is difficult to edit the source code. Replacing the html client side can be a good work around.

Put this function in your header:

<script type=”text/javascript”>
function findAndReplace(searchText, replacement, searchNode) {
if (!searchText || typeof replacement === ‘undefined’) {
// Throw error here if you want…
return;
}
var regex = typeof searchText === ‘string’ ?
new RegExp(searchText, ‘g’) : searchText,
childNodes = (searchNode || document.body).childNodes,
cnLength = childNodes.length,
excludes = ‘html,head,style,title,link,meta,script,object,iframe’;
while (cnLength–) {
var currentNode = childNodes[cnLength];
if (currentNode.nodeType === 1 &&
(excludes + ‘,’).indexOf(currentNode.nodeName.toLowerCase() + ‘,’) === -1) {
arguments.callee(searchText, replacement, currentNode);
}
if (currentNode.nodeType !== 3 || !regex.test(currentNode.data) ) {
continue;
}
var parent = currentNode.parentNode,
frag = (function(){
var html = currentNode.data.replace(regex, replacement),
wrap = document.createElement(‘div’),
frag = document.createDocumentFragment();
wrap.innerHTML = html;
while (wrap.firstChild) {
frag.appendChild(wrap.firstChild);
}
return frag;
})();
parent.insertBefore(frag, currentNode);
parent.removeChild(currentNode);
}
}
</script>

Run the function after the page has loaded, include the text to replace as a variable (Current Text, New Text):

findAndReplace(‘Current Text’, ‘New Text’);

BETT 2010 – Stand H9

bettI will be at BETT 2010 with CORE Education and Consulting Solutions. I will be doing a short SharePoint branding workshop.

BETT 2010 http://www.bettshow.com/

CORE Education http://www.coreeducation.co.uk

I will show how CSS can be used to customise vanilla SharePoint sites and how you can use Master Pages and Features to create richer SharePoint designs.

These workshops will be regular across all the days at BETT next week. If I’m free just ask me and I will start a workshop for you.

See you soon,
Tony

SCORM in SharePoint

When Uploading large SCORM content into document libraries you may need to change the max file upload in the web application settings and also in the web.config file as shown below:

Edit the httpRuntime tag in the web.config

<httpRuntime executionTimeout=”999999″ maxRequestLength=”184320″ />

New Custom Designs

Here’s one of my most recent designs for a school in Bradford. It’s SharePoint 2007 site using CSS, master pages and page layouts. It’s an interface for a primary school which hopefully makes it easier to use without losing the SharePoint functionality.

We had a nice opening ceremony which was attended by the local news paper (see below).

http://www.thetelegraphandargus.co.uk/district/district_bradford/4627331.School_blazes_trail_with_hi_tech_system/

I have posted a few of my new SharePoint Master Pages and Styles below

If you are interested in SharePoint solutions for schools please visit
http://www.coreuk.co.uk

I will post some more designs very shortly.

Getting external RSS feeds working through a proxy in SharePoint

  1. Find the web.config file for the web application
  2. e.g.

    C:\Inetpub\wwwroot\wss\VirtualDirectories\443

  3. Backup web.config and then open the file in notepad
  4. Append the  <defaultProxy> tag to include the proxy details
  5. <system.net>

    <defaultProxy>

    <proxy usesystemdefault=”false” proxyaddress=”http://proxy:80/” bypassonlocal=”true” />

    </defaultProxy>

    </system.net>

  6. Substitute http://proxy:80/ with your proxy address and port
  7. Save the web.config file

SharePoint Blueband MasterPage IE8 Drop-Downs

When using the Blueband masterpage or a custom masterpage, you may find that the drop-down menus don’t work in Internet Explorer 8 (IE8).

ie8 problem

There is a fix for internet explorer or you can view the page in compatibility mode. The only problem is you can’t expect all your users to know how to do this. Your site will be unusable to some of your users.

To fix this problem include the following meta tag into your masterpage:

<meta http-equiv=”X-UA-Compatible” content=”IE=EmulateIE7″ />

It will force IE8 to render the page as it would if it was still IE7. Maybe not the best of fixes but all that Microsoft provide at the moment. The SP2 update to sharepoint just adds this line into the Masterpages (this will not add it into custom masterpages that you have already made!).

Removing the Close Web Part Button

It can be very annoying having users accidently close web parts. It’s a long process to restore them.
To re-open a closed web part:

Go to Site Actions > Edit Page:
o Add a web part
o Advanced Web part gallery and options
o Select “Closed Web Parts”
o Drag-n-drop the web part back onto your page

To prevent this process from happening, try turning off the close web part button. It doesn’t remove the possibility of a user closing the web part but makes it much less likely to accidently happen!

For Each Web Part:

1.    Click on the web part menu and choose “Modify Shared Web Part” (as shown below)

2.    Expand “Advanced”

3.    Uncheck “Allow Close” (see below)

4.    Press OK

Inheriting a Master Page Across Site Collections

Ok, your publishing pages inherit fine but what if you want to inherit a master page on multiple site collections?

Unfortunately there is no easy way to do this if you want it to apply to the form pages as well, you could apply that master page to the entire web application but this would restrict one master page for the site. You need to create a site feature based on this master page template.

1. Open your master page in SharePoint Designer 2007 and make the appropriate changes to the site.

2. Insert your HTML, Javascript and attach your CSS, etc….

3. Copy and paste your master page code into notepad and save as masterpageName.master

4. Follow Heather Solomon’s excellent tutorial on creating a site feature and use your MasterpageName.master as the master page template

http://www.heathersolomon.com/blog/articles/servermstpageforsitecollect_feature.aspx

Once the site feature is activated you can goto Site Actions –> Site Settings –> Master Page and select your master page from the list (tick the box if you want it to apply to all the subsites)

Master Page Settings
Master Page Settings

Result – A custom master page which can be inherited by all the site’s children and the forms.