Solved

Sharepoint and Javascript.  Works in IE but not in Chrome.

Posted on 2013-12-05
4
545 Views
Last Modified: 2014-02-19
I have a Content Editor webpart on a Sharepoint page that is reference a file with the script below.  It works fine in IE but not in Chrome.  Going further into the issue i setup a simple alert("test"); and in IE it would work every time I refreshed the page.  In Chrome it would run once and never again.

What I basically am doing is pulling values from a query string and populating them in a DIV on the page.


<script language="javascript">

//GLOBAL VAR
var RegionVar;
var DepotVar;
var ProgramVar;

//GRAB URL PARAMETERS
function GetUrlValue(VarSearch){
//REMOVE "?" FROM STRING
    var SearchString = window.location.search.substring(1);
//SPLIT STRING WITH & SIGN
    var VariableArray = SearchString.split('&');
//LOOP
    for(var i = 0; i < VariableArray.length; i++){
        var KeyValuePair = VariableArray[i].split('=');
        if(KeyValuePair[0] == VarSearch){
            return KeyValuePair[1];
        }
    }

}


function SetDynamicData(){

RegionVar = GetUrlValue('Region');
DepotVar = GetUrlValue('depot');
ProgramVar= GetUrlValue('program');

document.getElementById("titlebardiv").innerHTML=(DepotVar.replace(/%20/gi, " "));
document.getElementById("programbardiv").innerHTML=(ProgramVar.replace(/%20/gi, " "));
}

window.onload=SetDynamicData ;

</script>

Open in new window

0
Comment
Question by:tyty4u2
4 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
Comment Utility
Hi,
which SharePoint version?

I would be really really careful to use window.onload - especially with SharePoint.

Could you simply try to replace
window.onload=SetDynamicData ;

Open in new window

with
_spBodyOnLoadFunctionNames.push("SetDynamicData");   

Open in new window


HTH
Rainer
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
SharePoint Designer 2010 has tools and commands to do everything that can be done with web parts in the browser, and then some – except uploading a web part straight into a page that is edited in SPD. So, can it be done? Scenario For a recent pr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now