How to automatically allow blocked content in IE? - javascript

I am using below code for sample menu.
<html>
<head>
<title>Tree Demo</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.jstree.js"></script>
<script type="text/javascript">
$(document).ready(function() {
/* $("#main").jstree({
"themes" : {
"theme" : "default",
"dots" : false,
"icons" : false
},
"plugins" : [ "themes", "json_data", "ui"],
"json_data" : {
"ajax" : {
"url" : "jsondata.json",
"data" : function (n) {
return { id : n.attr ? n.attr("id") : 0 };
}
}
}
});
$("#main").bind("open_node.jstree", function (e, data) {
// data.inst is the instance which triggered this event
console.log(data);
console.log($.data(data.rslt.obj[0],"folder_name"));
});
$("#main").bind("select_node.jstree", function (e, data) {
// data.inst is the instance which triggered this event
console.log(data);
console.log($.data(data.rslt.obj[0],"folder_name"));
}); */
$("#main1").jstree({
"themes" : {
"theme" : "default",
"dots" : false,
"icons" : false
},
"plugins" : [ "themes", "html_data"]
});
});
</script>
</head>
<body>
<div id="main1">
<ul>
<li>Home Folder
<ul>
<li>Sub Folder1</li>
<li>Sub Folder2</li>
</ul></li>
<li>Shared Folders
<ul>
<li>Shared Folder1</li>
<li>Shared Folder2</li>
</ul></li>
</ul>
</div>
<div id="main">
</div>
</body>
</html>
when i run the above code in IE browsers it shows top of the page(below the URL bar) like
" To help protect your security , internet explorer has restricted this webpage from running scripts or Activex controls that could access your computer. click for options.. "
when i rightclick and click allowed blocked content, it runs.but i want without this popup message i need to run the code...how can i automatically run this one?...

There is a code solution too. I saw it in a training video. You can add a line to tell IE that the local file is safe. I tested on IE8 and it works. That line is <!-- saved from url=(0014)about:internet -->
For more details, please refer to https://msdn.microsoft.com/en-us/library/ms537628(v=vs.85).aspx
<!DOCTYPE html>
<!-- saved from url=(0014)about:internet -->
<html lang="en">
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function () {
alert('hi');
});
</script>
</head>
<body>
</body>
</html>

I believe this will only appear when running the page locally in this particular case, i.e. you should not see this when loading the apge from a web server.
However if you have permission to do so, you could turn off the prompt for Internet Explorer by following Tools (menu) → Internet Options → Security (tab) → Custom Level (button) → and Disable Automatic prompting for ActiveX controls.
This will of course, only affect your browser.

You have two options:
Use a Mark of the Web. This will enable a single html page to load. It See here for details. To do this, add the following to your web page below the doctype and above the html tag:
<!-- saved from url=(0014)about:internet -->
Disable this feature. To do so go to Internet Options->Advanced->Security->Allow Active Content... Then close IE. When you restart IE, it will not give you this error.

If you are to use the
<!-- saved from url=(0014)about:internet -->
or
<!-- saved from url=(0016)http://localhost -->
make sure the HTML file is saved in windows/dos format with "\r\n" as line breaks after the statement.
Otherwise I couldn't make it work.

Steps to configure IE to always allow blocked content:
From Internet Explorer, select the Tools menu, then the Options...
In the Internet Options dialog, select the Advanced tab...
Scroll down until you see the Security options. Enable the checkbox
"Allow active content to run in files on My Computer".
Close the dialog, and quit Internet Explorer. The changes will take
effect the next time you start IE.
The Blocked Content is a security feature of Windows XP Service Pack 2. If you do not have SP2 installed, then you will never see this message.
From: How To Allow Blocked Content on Internet Explorer

That's something I'm not sure that you can change through the HTML of the webpage itself, it's a client-side setting to tell their browser if they want security to be high. Most other browsers will not do this but from what I'm aware of this is not possible to stop unless the user disables the feature.
Does it still do what you want it to do after you click on 'Allow'? If so then it shouldn't be too much of a problem

Alternatively, as long as permissions are not given, the good old <noscript> tags works. You can cover the page in css and tell them what's wrong, ... without using javascript ofcourse.

Related

Load html with javascript issue in safari browser

I'm struggling on this question for whole day, so maybe someone could help.
I want to load settings.php page, which includes javascript/jquery code with usual html, into index.php on button click.
Here are the code snippets:
Index.php
<head>
<script type="text/javascript">
function loadSettingsPage (){
$('#myResults').load('settings.php', function (){ });
}
</script>
</head>
Settings.php
<div class="tabsWrapper">
<ul class="tabs">
<li data="sections" onclick="setTab('sections')">Product categories</li>
<li data="suppliers" onclick="setTab('suppliers')">Suppliers</li>
</ul>
</div>
...
<script type="text/javascript">
function setTab(currentTab = "sections"){
//some code goes here
};
$(document).ready(function (){
//document ready code goes here with click events
}
</script>
The question is, how to load/include Settings.php file into index.php file so that all javascript code included click events in $(document).ready function is executed in safari browser as well. Now it works perfectly with all browsers but safari.
You're trying to use the EcmaScript 6 feature of default parameters. This isn't yet implemented in Safari, Opera, or Internet Explorer, according to MDN.
Use an explicit check for whether the argument is set:
function setTab(currentTab) {
currentTab = currentTab || "sections";
// some code goes here
}
You need to be very careful about using new ES6 features, many of them are not yet implemented in Safari, and they'll never be implemented in old IE versions.

letter in quotes appearing just after body tag

We've just launched our new Magento site and the letter 'c' is appearing in quotes immediately after the tag. It's not showing up before on my local machine or on our QA site, I've checked the template files and it is not there either. I'm almost certain it can not be a code issue as we have the same code running locally and on our QA site under version control with GIT.
We've cleared the cache and I've tried checking to see if JavaScript was inserting it with the chrome dev tools but could find nothing.
Strangely, the 'c' is not in the view source document but I can see it with the chrome inspector.
I also don't think it can be coming from Magento CMS Pages/Blocks as it loading immediately after the tag.
thanks for the link. after reviewing the page source, you have an extra c character in the header area:
<!-- END GOOGLE ANALYTICS CODE -->
c<script type="text/javascript">//<![CDATA[
var Translator = new Translate([]);
//]]></script>
Notice that c before the script tag?
Just in support to Benny Lin's very helpful answer.
What was happening was we had our Google Analytics code loading from a template file which contained the stray letter 'c'. We could see this on our local machines as this templates was disabled in the Magento admin settings, but not on production.
This issue seems to demonstrate that when a stray letter appears within the <body> tags on your dev tools inspector and not the view source page it may be because it is in the <head> section. The browser seems to push all poorly formatted html from the <head> section into the <body> section when rendering.
For example if you open the below html in the chrome browser you will see what I mean:
<!DOCTYPE html>
<html>
<head>
c<title>Title of the document in head</title>
<script type="text/javascript">
var test = "test";
</script>
</head>
<body>
The body of the document......
</body>
</html>
Also while we were searching for the stray letter, we were ably to remove it with the below JavaScript that targets the offending XML node in the DOM with an XPath expression and removes that node only.
<script type="text/javascript">
function _x(STR_XPATH) {
var xresult = document.evaluate(STR_XPATH, document, null, XPathResult.ANY_TYPE, null);
var xnodes = [];
var xres;
while (xres = xresult.iterateNext()) {
xnodes.push(xres);
}
return xnodes;
}
jQuery(_x('//html/body/text()[contains(.,"c")]')).remove();
</script>

PDF Reader not installed on browser - Wish to Auto download

<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="gistfile1.js"></script>
</head>
<body>
<p id="divPDF">Can't see the PDF?</p>
</body>
<script type="text/javascript">
var info = getAcrobatInfo();
if (info.acrobat == false){
window.location = "empty.pdf";
} else {
document.getElementById("divPDF").innerHTML = "<object data='empty.pdf' type='application/pdf' width='100%' height='100%'><p class='helpContent'>Can't see the PDF? Try <a href='empty.pdf' download='empty.pdf'>downloading the file</a>. If you're still having trouble, <a href='/contactUs.jsp'>contact us</a> or email us directly at <a href='mailto:support#guitarinstructor.com'>support#guitarinstructor.com</a>.</p></object>";
}
</script>
</html>
Here's what I'm looking at doing. IF the getAcrobatInfo TRUE, display the PDF.
If the getAcrobat returns FALSE, then automatically download the PDF.
I thought this would work on a window.location = "URL OF THE PDF", my browser still attempts to display it.
Is there any javascript or jQuery that I can implement that will allow me to force an auto download if the user's browser doesn't have a PDF Reader plugin?
Typically you must set the Content-disposition header to attachment to encourage a browser to download a file instead of displaying it. If you can do this, and your client side plugin detection works, you could edit your server side code to have a different URL depending on the disposition you want to send, and have that in your object src attribute or location.replace argument.
Additionally, in HTML5 there is a download attribute for the <a> tag, with an optional filename as the attribute value. Support for this is not in every browser.
Download
Note that a very common practice is to have a single link with a small blurb informing a user how to download a file (e.g. using the right mouse button).

Javascript image viewer not working in internet explorer

I have made a similar kind of image viewer mentioned in below site for my website.
http://www.javascriptkit.com/script/script2/backbox/
The image viewer is working fine in Chrome but not working in Internet Exlporer;
I have not given my website details for security reasons but you view the issue by copy pasting below link in Chrome and Internet Explorer.
http://www.javascriptkit.com/script/script2/backbox/
Click the Image in above link and see the error in internet explorer & see the same in other browser to see its working condition...
PFB snap shot
Could any one of you tell why is not working in internet explorer ?
Error Msg from IE F12 devolper tools console area is :
SCRIPT5007: Unable to get value of the property 'replace': object is
null or undefined effects.js, line 1 character 1747
effects.js =
http://www.javascriptkit.com/script/script2/backbox/js/effects.js
If you need sample js files, please get that from http://www.javascriptkit.com/script/script2/backbox/backboxfiles.zip
HTML used is;
<link rel="stylesheet" href="backbox.css" type="text/css" />
<script type="text/javascript" src="js/prototype.compressed.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<script type="text/javascript" src="js/dhtmlHistory.js"></script>
<script type="text/javascript" src="js/customsignsheader.js"></script>
<div onclick="dhtmlHistory.add('location1',{message: 'backbox'});countdown()">
<a href="images/babyhand.jpg" rel="lightbox[slide]" caption="A Bunch of Grapes">
<img src="images/sunset.jpg" alt="lime" width="400" height="300" border="0" /></a>
</div>
<script type="text/javascript" src="js/customsignsfooter.js"></script>
regarding about your concern why this occurs in IE and not in chrome, that's because of this condition if(/MSIE/.test(navigator.userAgent) which is true when your browser is IE
for correcting the issue, as you said in a comment you can add a 'undefined' condition.
just replace this line:
if(/MSIE/.test(navigator.userAgent)){Element.setStyle(_10,{filter:Element.getStyle(_10,"filter").replace(/alpha\([^\)]*\)/gi,"")+"alpha(opacity="+_11*100+")"});}
with:
if(/MSIE/.test(navigator.userAgent)){var filterStyle=Element.getStyle(_10,"filter");if(typeof(filterStyle)!="undefined"){Element.setStyle(_10,{filter:filterStyle.replace(/alpha\([^\)]*\)/gi,"")+"alpha(opacity="+_11*100+")"});}}
and this line:
if(/MSIE/.test(navigator.userAgent)){Element.setStyle(_10,{filter:Element.getStyle(_10,"filter").replace(/alpha\([^\)]*\)/gi,"")});}
with:
if(/MSIE/.test(navigator.userAgent)){var filterStyle=Element.getStyle(_10,"filter");if(typeof(filterStyle)!="undefined"){Element.setStyle(_10,{filter:filterStyle.replace(/alpha\([^\)]*\)/gi,"")});}}
in the effects.js file
Open developer tools in IE (press F12) and click the "Console" tab. You should be able to see in there that there's an error with the effects.js script :
SCRIPT5007: Unable to get value of the property 'replace': object is null or undefined
effects.js, line 1 character 1747
That should at least give you somewhere to start looking.
...and if you're that lazy, the actual line of code it's failing on is this :
Element.getStyle(_10,"filter").replace(/alpha\([^\)]*\)/gi,"")
The getStyle call is clearly returning null, so subsequently calling replace will fail.
Internet Explorer does not currently have full HTML5 support. Any manipulation of HTML5 related tags or elements will therefore fail. It is worth trying to include the html5shiv library, which tricks IE into believing these tags exist.

JS how to check if webpage has been added as homepage?

I am trying to make something similar like Google on IE. They create a "Make Google your homepage" script for IE.
This is what I have so far:
<script type="text/javascript">
$(document).ready(function () {
$("#no_thanks").click(function () {
$(".lightbar").hide();
}); });
</script>
<!--[if IE]>
<div class="lightbar">Come here often? Make xxx your homepage.
<span class="sure">Sure!</span>
<span class="nothanks"><a id="no_thanks" href="#" onClick="_gaq.push(['_trackEvent', 'HomePage', 'No', 'Set as Home page']);">No Thanks</a></span>
</div>
<![endif]-->
I also added some Google Analytics.
What happens is that the script works, it does set the homepage, but the "lightbar" doesn't disappear when I restart the browser (i'm not talking about the jQuery script).
Any ideas?
Imho there is no solid way.
the best you could do is to add a querystring to the url that is under the add-as-homepage link. like:
www.example.com/homepage.html?isbookmark=true
or
www.example.com/homepage.html?ishomepage=true
then just check if the querystring exists in the url when the document is called. Then it is initiated from this button or a bookmark or a homepage.

Categories

Resources