I've written some very simple code on Internet Explorer 8 and I don't understand why nothing happens when I open the page with IE (why the text 'test' doesn't appear on the page).
I've tried on Firefox and Chrome and it works perfectly.
my code :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso 8859-1" />
<script type="text/javascript">
function display() {
output.innerHTML+='test';
}
</script>
</head>
<body onload="display()">
<div id="output">
</div>
</body>
</html>
Edit : let IE change your setting, don't do it by hand or it gets weird :-))
document.getElementById('output').innerHTML += 'test';
Try:
function display() {
document.getElementById('output').innerHTML+='test';
}
Related
The following code doesn't work in Chrome, but it work in Firefox
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<main>
<button onclick="origin.haha()">This is a test button</button>
</main>
<script>
A = {
haha: function() {
alert(5);
}
}
</script>
<script>
var origin = A;
</script>
</body>
</html>
When I click the button, I was expected to see the alert message, but when I open the code in chrome, and click button, it raise an error which said that the origin.add is not a function, I have check it, and I think it was because that origin variable is a builtin variable, and it's identified to window.origin. And chrome doesn't allow user redefined the variable.
But when I open chrome debug console, and enter origin.haha(), it can show the alert message...
And which make me more confusing, the following code can work in chrome.
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<main>
<button onclick="testFunc()">This is a test button</button>
</main>
<script>
A = {
haha: function() {
alert(5);
}
}
</script>
<script>
var origin = A;
testFunc = function() {
origin.haha();
}
</script>
</body>
</html>
Can anyone tell me that what happened to the origin variable? Why chrome can show alert message in the 2nd code but can't show alert message in the 1st code?
I wish that I have describe the question clearly...
I tried my code on chrome, opera, firefox and edge but it's not working. My onload code works perfectly, but onunload doesn't work on all. Do not know why?
Here is my code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body onload="loaded()" onunload="unloaded()">
<script type="text/javascript">
function loaded(){
alert("The page loaded!");
}
function unloaded(){
alert("Come again!");
}
</script>
</body>
</html>
Some operations are not allowed on onunload event showing alert is one of them. Check this answer.
You can use below code to display a warning message to users.
window.onbeforeunload = function(e) {
return 'Bye now!';
};
when you invoke the unload function,the DOM is completely unload now.
So there can't show an alert window for you.
But you can see the log printed in the console if you use
---> console.info("Come again!");
Already searched the whole web for a solution. First i used jqplot for the visualization of a mysqldatabase, but with growing arrays i'm trying to switch to dygraph, moreover its optimiesed for timedate, the problem is i cannot get it to work on ie explorer <9 especially with regard to the document modus. also tested ietester....
the page of dygraph itself works with the graphs, copied the important parts from it but still cannot get it working, maybe someone can show me my mistake or is it better not to use dygraph?anyone makes use of this and gets it working for internetexplorer 6-8?
The problem is the jquery document.ready function without it everything works fine...
<!DOCTYPE html>
<html>
<head>
<!-- Framework,Diagramm-Klasse,Jqplot,Jqplot Plugin -->
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Konfigurationstool</title>
<script type="text/javascript" src="jquery-test.js"></script>
<!--[if IE]>
<script type="text/javascript" src="excanvas.js"></script>
<![endif]-->
<script type="text/javascript" src="dygraph-combined.js"></script>
</head>
<body>
<script language="javascript" type="text/javascript">
$(document).ready(function()
{
g = new Dygraph(document.getElementById("diagrammpreview"), [[1,10,100], [2,20,80], [3,50,60], [4,70,80]]
);
});
</script>
<div id="diagrammpreview" style="height:500px;width:500px;"></div>
</body>
</html>
thanks in advance
What does the debug console in IE say the problem is? It's probably either a race condition or a conflict with the $ variable. You can try to use a pure javascript alternative the ready/load function such as:
window.onload=function() {
g = new Dygraph(document.getElementById("diagrammpreview"), [[1,10,100], [2,20,80[3,50,60], [4,70,80]]);
});
I had the same problem in IE and FF.
$(window).load(function) {
instead of
$(document).ready(function) {
helped, together with including the jquery library directly into the html file (although it was included in my CMS)
I'am developing a web-application that allows to select parts of an html document and put some kind of annotation on it.
To get hold of the selected text I use window.getSelection() which works pretty fine in IE9, FF, and Safari.
However I run into trouble when using the same page on my IPad 2:
If I just select a word by tapping it for a sec, window.getSelection() returns the proper selection.
If I create a text range ( as discribed here http://blog.laptopmag.com/how-to-select-copy-and-paste-text-on-the-ipad ) always return "null".
I've already examined the window, document and related event objects - but without success...
Any help would be really appreciated!
Edit: Just a small example. Select a text and press the button. On Safari (PC) the function prints the selected value...
<html>
<body>
<script>
function a()
{
alert(window.getSelection());
}
</script>
Hello World! <input type="button" onclick="a();"
</body>
</html>
Okay finally I've solved the problem: As Tim assumed the click events causes to selection to collapse. I consider this as rather strange behavior as on regular Safari this does not happen.
However, the solution is not to use the click event. Instead of I'm using "vlick" provided by the jquery mobile.
Full working example:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
</head>
<body>
Hello World! <input type="button" id="button1" />
<script>
function a()
{
alert(window.getSelection());
}
$("#button1").bind("vclick",a);
</script>
</body>
</html>
I'm new to JS and I need to detect whenever someone enters to my site with the Interent Explorer Browser. So, I made the following code and the div that I created is being scripted on other web browsers I assume the problem is with the .getElementById or such.
So after the talking, here's the code:
<html>
<head>
<script type="text/javascript">
var browserName=navigator.appName;
if (browserName=="Microsoft Internet Explorer")
{
document.getElementById("example");
}
</script>
</head>
<body>
<div id ="example">You're Using Interent Explorer. </div>
</body>
</html>
Thanks alot for helpers.
These HTML comments are only rendered by internet explorer
<body>
<!--[if IE]>
<div id ="example">You're Using Interent Explorer. </div>
<![endif]-->
</body>
most of the time it's for CSS, because you can target IE 6,7,8,etc or greater than IE 7:
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="all-ie-only.css" />
<![endif]-->
Example
1 To begin with, you should hide the div (display:none).
2 You need to actually do something with the div in your script (fiddle).
<html>
<head>
<script type="text/javascript">
window.onload = function(){
if (navigator.appName === "Microsoft Internet Explorer")
{
document.getElementById("example").style.display = "block";
}
}
</script>
</head>
<body>
<div id ="example" style="display:none;">You're Using Interent Explorer. </div>
</body>
</html>
Otherwise, you could just add the div contextually (fiddle)
window.onload = function(){
if (navigator.appName === "Microsoft Internet Explorer")
{
document.body.appendChild(
document.createElement("div")
).appendChild(
document.createTextNode("You're Using Interent Explorer"));
}
}
First of all, JavaScript should not be used to detect browsers. Like, for Chrome, it gives the result "Netscape". Anyways to answer your question, what about an alternative:
<html>
<head>
<script type="text/javascript">
var browserName=navigator.appName;
if (browserName=="Microsoft Internet Explorer")
{
document.getElementById("example").innerHTML="You're using Internet Explorer!";
}
</script>
</head>
<body>
<div id ="example"></div>
</body>
</html>
What it does is it will have no content in the specific div element, that is, example. Only if JavaScript detects that one is using Internet Explorer, it writes "You're using IE" in the div element. For example, you can check out http://www.ducksearch.in/ using Internet Explorer. It shows an alert box that some features may be missing if you use IE. Very basic JavaScript, indeed :)
Good luck on your way ahead, and all the best coding in JavaScript.