Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

In my masterpage, I've loaded a simple javascript file from /_layouts/myfolder/myjs.js - and the script loads and runs in Firefox (even in different instances and with different plugins) but not in IE 10, nor in Chrome.

The script is just this:

alert("bob");

The popup blocker is disabled, and Security Zone is set to low. Javascript is enabled.

I've tried regular old js script links, and I've also tried the delayed loading, like this:

<SharePoint:ScriptLink ID="myScriptLink" runat="server" Name="/_layouts/mylib/myscript.js" LoadAfterUI="true" OnDemand="false"/>

What could cause this?

share|improve this question
1  
Have you cleared the browser cache? –  Robert Lindgren Jul 18 '13 at 17:14
    
Yes - I cleared everything. The master loads - I can see the stylesheets working. –  BGM Jul 18 '13 at 18:09
1  
Could it be related to the security zone? –  Robert Kaucher Jul 18 '13 at 18:34
1  
Does it help if you wrap it in a method that you call from ExecuteOrDelayUntilScriptLoaded or any other body onload event? Or is it just when it is unwrapped that it is not executed? –  Robert Lindgren Jul 18 '13 at 18:54
1  
Ah, sorry fellas. I'm a dunce. I added the /* to comment out the script, but I didn't scroll down far enough to see that another comment cancelled the comment. Which means it actually is working and there is something else wrong in the script. I'm going to delete my question. Thanks for helping. –  BGM Jul 18 '13 at 18:55

2 Answers 2

up vote 0 down vote accepted

I am used to coding in autohotkey where I can do this by way of optional parameters:

somefunction(parameter, optionalparam="aConstant"){
   ;some stuff
}

However you can't do it that way in Javascript. Instead you do it like this:

function somefunction(parameter, otherparameter){
    if(!otherparameter)
         otherparamteter = something;
}

Apparently, Firefox will still run the parts of the script that haven't yet failed. IE and Chrome both dump the entire script and don't do anything at all. That means that an alert("bob"); at the top of the script will always run in Firefox, even if part of the code below it is wrong - but in IE and Chrome, nothing happens.

Interesting!

share|improve this answer

Try to load jquery and fire alert inside ready function of Jquery and check.

Also, it can possible if you already added jquery in master page and something conflict on page load thats why not working in IE.

If possible, show me your head portion of master page.

share|improve this answer
    
The OP has already given the answer below –  Robert Lindgren Jul 19 '13 at 6:34
    
I have to wait till tomorrow to accept my answer... –  BGM Jul 19 '13 at 13:46

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.