Disable all JavaScript and jQuery in one HTML page - javascript

I have a WordPress website and I have installed one plugin and the plugin has some problems in IE6 browser.
So, I want to disable that jQuery plugin when the page is viewed with the IE6 browser.
So now I need a jQuery statement to disable ALL other statements that are loading from other JS files.

use Downlevel-revealed conditional comments :
<!--[if lte IE 6]><![if gte IE 7]><![endif]-->
<!-- keep your script in between these two comments,
it will work in all browser except ie -->
<!--[if lte IE 6]><![endif]><![endif]-->
Explained here : Hiding some HTML from IE6?

I'm not entirely sure why IE6 is even on your agenda, but to each their own.
If it were me I would write something like this.
<!doctype html>
<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->....
.....
(function ($) {
"use strict";
// Detect IE 6
var greatGreatGranddadsBrowser;
if ($('html').is('.ie6')) {
greatGreatGranddadsBrowser = true;
}
if (greatGreatGranddadsBrowser) {
// Remove the elements that you don't want loaded
// Tell the users to seriously consider coming into the real world
} else {
// Do whatever else you need to do
}
}(jQuery));

Related

Inline Scripting issue in windows 10 apps with Microsoft edge

Im developing Windows 10 store apps Javascript/Html and since there is Microsoft EDGE in apps as the browser, inline scripting no longer works. If i put the code in an external file, the page loads, but none of the click events work. Is there any solution for this. Small example where onclick attribute does not work.
Code
default.html 7 default.js
// For an introduction to the Blank template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232509
function gored() {
document.body.style.backgroundColor = red;
}
(function () {
"use strict";
WinJS.Binding.optimizeBindingReferences = true;
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
var isFromBackground = false;
app.onactivated = function (args) {
var localSettings = Windows.Storage.ApplicationData.current.localSettings;
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
// TODO: This application has been newly launched. Initialize
// your application here.
} else {
// TODO: This application has been reactivated from suspension.
// Restore application state here.
}
args.setPromise(WinJS.UI.processAll());
}
};
app.oncheckpoint = function (args) {
// TODO: This application is about to be suspended. Save any state
// that needs to persist across suspensions here. You might use the
// WinJS.Application.sessionState object, which is automatically
// saved and restored across suspension. If you need to complete an
// asynchronous operation before your application is suspended, call
// args.setPromise().
isFromBackground = true;
};
app.start();
})();
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>App1</title>
<!-- WinJS references -->
<!-- To get the latest version of WinJS, go to: http://go.microsoft.com/fwlink/?LinkId=533245 -->
<link href="WinJS/css/ui-dark.css" rel="stylesheet" />
<script src="WinJS/js/WinJS.js"></script>
<!-- App1 references -->
<link href="/css/default.css" rel="stylesheet" />
<script src="/js/default.js"></script>
</head>
<body>
<p>Content goes here</p>
<button onclick="gored()"> Click Me</button>
</body>
</html>
I went into detail about this in a blog post.
Windows HTML5 apps have a strict security setting, especially when it comes to injecting code at runtime via JavaScript. I ran into this issue before as well.
You can wrap the function that you are using to inject the Javascript with another function, MSApp.execUnsafeLocalFunction().
When attempting to dynamically insert a div, Windows 8 throws an error. Specifically, it’s when trying to use something like:
div.innerHTML = "A string of some stuff"
HTML1701: Unable to add dynamic content ' a' A script attempted to inject dynamic content, or elements previously modified dynamically, that might be unsafe. For example, using the innerHTML property to add script or malformed HTML will generate this exception. Use the toStaticHTML method to filter dynamic content, or explicitly create elements and attributes with a method such as createElement. For more information, see http://go.microsoft.com/fwlink/?LinkID=
Reason:
The reasoning behind all of these problems is the same, so I’ll just state it here once for the sake of brevity. `Microsoft fears that the string can be intercepted somewhere along the line, and malicious content can be added to the values of your string.
Work Around:
The big issue with this method is that you’re trying to use innerHtml. Instead, use .append.
That still won’t work if you just try to pass in a string, however. What you need to do is set your string to a variable, then pass in that variable. If you do not create an object (that is, setting the string to a variable) then this will not work. If you just try to use a string, then you’ll see nothing but text where the div should be.
Here’s a single line example:
$panel.append('<'img src="' + item.thumbImageUrl +'" >');
If you try to pass that in, Windows 8 will throw the error seen above. Even if I wrap that in MSApp.execUnsafeLocalFunction() I will still see an error.
The workaround is as follow:
var appendString = '<'img src="' + item.thumbImageUrl '" >';
$panel.append(appendString);
Because I’m now taking that string and setting it to a variable (thereby turning it into an object), Windows 8 will allow me to pass in that object and create dynamic content.
Even then, it will occasionally throw the error above. HOWEVER, if you were to wrap that object in MSApp.execUnsafeLocalFunction(), you would then be in the clear. WinJS offers a function to wrap your own functions in, which allows you to basically say “I take responsibility for this function, and I assure you it’s safe.” That function is called: MSApp.execUnsafeLocalFunction().
So the final solution looks like this:
var appendString = '<'img src="' + item.thumbImageUrl '" >';
MSApp.execUnsafeLocalFunction(function() {
$panel.append(appendString);
});
You can read more about this issue here.
Further Reading:
execUnsafeLocalFunction from MSDN
TutsPlus tutorial on jQuery and Win8
I had a similar problem and found that a script read in the header did not work but when I moved it to the body, it did:
WORKS ON MOST BUT NOT ALL PAGES WITH 'EDGE'. WORKS WITH ALL PAGES ON ALL OTHER BROWSERS:
LT script type="text/javascript" src="../ie5.js" GT LT /script GT
LT script type="text/javascript" src="../common_functions.js" GT LT /script GT
LT /head GT
LT body GT
WORKS ON ALL PAGES WITH 'EDGE' AND OTHER BROWSERS:
LT /head GT
LT body GT
LT script type="text/javascript" src="../ie5.js" GT LT /script GT
LT script type="text/javascript" src="../common_functions.js" GT LT /script GT
Why? Only Microsoft will know.

JQuery Signature not working for IE <= 9

I am using JQuery Singature and I encountered this Error Message for above IE version:
Message: Canvas element does not support 2d context. jSignature cannot proceed.
update : After Added the (;) in the flashcanvas.js
The Problem is the Same:
Message: Expected ';'
flashcanvas.swf
Code: 0
I have downloaded the flashcanvas.swf and flashcanvas.js from:
https://github.com/brinley/jSignature/blob/master/libs/flashcanvas.js
https://github.com/brinley/jSignature/blob/master/libs/flashcanvas.swf
these two files I placed them in a Folder called Script.
It does not matter if I include or did not include flashcanvas.swf What I need to do?
here the javascript
<!--[if lte IE 9]>
<script type="text/javascript" src="Script/flashcanvas.js"></script>
<script type="text/javascript" src="Script/flashcanvas.swf"></script>
<![endif]-->
<script type="text/javascript" src="Script/jSignature.js"></script>
<script type="text/javascript">
$(document).ready(function (){
$("#divSignature").jSignature({width:400, height:140, mousedown:function(){}});
});
</script>
Just a syntax error, simply update the following at line 928 of flashcanvas.js:
function getSwfUrl(window) {
return ( (window[FLASH_CANVAS + "Options"] || {})["swfPath"] || BASE_URL ) + "flashcanvas.swf"; //Added semicolon
}
IE tend to be less lenient towards Javascript errors, which can be a good thing for programmers learning the language. Browsers like Chrome can accommodate a fair amount of JS errors and still correctly execute a script.

make a condition to the IE browser?

<script language = "javascript">
if (navigator.appName == "Microsoft Internet Explorer") {
begin = navigator.userAgent.indexOf("MSIE ") +
"MSIE ".length;
if(navigator.userAgent.indexOf(";", begin) > 0) {
end = navigator.userAgent.indexOf(";", begin);
} else {
end = navigator.userAgent.indexOf(")", begin)
+ 2;
}
document.getElementById("targetDiv").innerHTML =
"You are using Internet Explorer " +
navigator.userAgent.substring(begin, end);
}
}
</script>
why when make a condition to the IE browser,there added an else part? what's the meaning and effect of it? thank you,
You shouldn't use Javascript to sniff out Internet Explorer. Welcome to HTML conditional comments:
FOR DETECTING IE:
<!--[if IE]>
<!-- Add IE script file here -->
<![endif]-->
FOR DETECTING ANYTHING EXCEPT IE:
<!--[if !IE]> -->
<!-- Add non-IE script file here -->
<!-- <![endif]-->
Javascript isn't a good solution for browser sniffing because you should only use it as a way to "progressively enhance" a website. If your website is going to break when someone doesn't have Javascript enabled, then that's not acceptable. Build your website and use Javascript to add the effects necessary to create a better experience.
This is especially true if you already have a native way of detecting for Internet Explorer. Why not use a method which will work in all browsers as opposed to a method that will work in browsers that only allow Javascript? You can never be so sure.

What would make Internet Explorer NOT process conditional comments properly?

I'm writing JSP pages and using Tomcat, and it needs to work for IE 7 in addition to Firefox and Chrome (client needs).
In my program, I include both pieces of code. It works properly for non-IE browsers.
My problem is that CODE A does not work properly for IE, in that it treats it like a comment rather than a conditional comment that it should be reading. Any idea why this would happen and how to fix it?
<script type="text/javascript">
...
<!-- CODE A -->
<!--[if IE]>
url = "http://" + "..." + "&var=1";
<![endif]-->
<!-- CODE B -->
<!--[if !IE]> -->
url = "http://" + "..." + "&var=1";
<!-- <![endif]-->
...
</script>
Conditional HTML comments only work in HTML. JavaScript is not HTML. Rather use conditional JS comments in JS:
var IE = /*#cc_on!#*/false;
(only IE will interpret the ! which effectively makes it true)
Then you can use it as follows
if (IE) {
url = "http://" + "..." + "&var=1";
} else {
url = "http://" + "..." + "&var=1";
}
Feature detection should however be preferred in JS.

Javascript :- ExtJS el.dom.innerHtml Removed <link> and <style> tags on IE only It works fine Firefox. when el.dom.innerHtml assign html string

For FireFox el.dom.innerHTML
<title>Test</title>
<link rel="stylesheet" type="text/css" href="common.css">
Test
For IE el.dom.innerHTML
Test
In FF the returned el.dom.innerhtml includes the and tag but in IE it does not. Are these filtered out by Ext in anyway and if so why?
Below this forum link give solution to override the Ext.element.Update method.
Ext.override(Ext.Element, {
update : function(html, loadScripts, callback){
}
http://www.sencha.com/forum/showthread.php?30110-internet-explorer-autoLoad-css-not-applied
But I have question where I add this function which ExtJs files. because ext-all-2.2.js and ext-base-2.2 is core files of ExtJs Libarary. I put this code in ExtExtension-2.2.js file but Override Update method doesn't fire when assign
this.el.dom.innerHtml=Markup (markup is string which contain html string.)
Please help me which ExtJs file I put function . Ext.Override(Ext.Element) Update Method?
That override simply needs to run sometime after the Ext scripts are loaded. So include a javascript file after including the Ext files, and the method will be overridden.
<script type="text/javascript" src="/path/to/ext-all-2.2.js"></script>
<script type="text/javascript" src="/path/to/myscript.js"></script>
The in myscript.js:
Ext.override(Ext.Element, {
update : function(html, loadScripts, callback){
...
}
}
Remember though, that Ext isn't magic. It can't automatically fire the update function when simply assigning innerHTML, as that is handled entirely by the browser. Rather, use the update function directly, and that will update the innerHTML:
Instead of:
this.el.dom.innerHtml=Markup;
use:
this.el.update(Markup);

Categories