I have the following java script code
$("#btn_Print").click(function (e) {
e.preventDefault();
var printWindow = window.open("../private/analysisPrint.htm");
printWindow.print();
printWindow.close();
return false;
});
and the analysisPrint.htm page contains.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<div>
<h4>
Print</h4>
First print page
</div>
</body>
</html>
The problem I am having is that I am always getting a blank page being printed. When i open the page directly and print its fine.
Any Ideas
You can (and probably should) wait for the page to load completely (including images):
var printWindow = window.open("../private/analysisPrint.htm");
$(printWindow).on('load', function() {
printWindow.print();
printWindow.close();
});
Related
I have the following simple java script code which does not execute when I press the Refresh button in Microsoft Edge. None of the 3 alerts execute at refresh. It works well with Chrome.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script type="text/javascript">
jQuery(function() {
alert('jQuery');
});
function func() {
alert('func');
}
function load() {
alert('load');
}
window.onload = load();
func();
</script>
</head>
<body>
</body>
</html>
This code can be put in an HTML file (test.html).
Why does this happen? Thank you.
Maybe use window.addEventListener("load", load, false);. Sometimes, if one thing doesn't work, another will.
When sample below code loads in IE9, it works correctly, but when loads in an html control in an application, scrollHeight not updated in onscroll event handler when I change the innerHTML content in the handler, and therefore the alert not to be displayed.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script>
function f()
{
var nBodyHeightOld = document.getElementById("div1").scrollHeight;
document.getElementById("div1").innerHTML += '<div>It is a test!</div>';
if (document.getElementById("div1").scrollHeight != nBodyHeightOld)
alert('scrollHeight changed!');
}
</script>
</head>
<body>
<div id='div1' style='overflow:scroll; height:300px' onscroll="f()">
<div style='height:400px'></div>
</div>
</body>
</html>
Becuse the application use IE8. To force application use IE9 add meta tag to html:
<meta http-equiv="X-UA-Compatible" content="IE=9" >
EDIT: It does work (sorry). Something in this script is causing it to stop in google chrome:
function checkLocation() {
var loc = top.location.href;
var suffix = "subpage.html";
if (loc.indexOf(suffix, loc.length - suffix.length) !== -1) {
top.location.href = "index.html";
}
}
Original post:
I have IE 9, FF 3.6.3, Chrome (18.0.1025.151) and Safari 5.1.5 all installed.
This works in all of the browsers except google chrome.
I have a HTML layout which contains a named iframe. The iframe src changes to display the different pages. On one of the pages I have a script which is loaded onLoad in the body tag. This script doesn't load when the page is loaded in the iframe in google chrome only - it works fine in other browsers. Also, if I load the page directly into google chrome (not via an iframe) it works just fine.
How do I fix this?
Here is an example code:
index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html> <head> <title> Example Page </title> </head>
<body> View subpage<BR/>
<iframe name="targetFrame"> </iframe>
</body>
</html>
subpage.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html> <head> <title> Subpage </title>
<script type="text/javascript" src="subpage.js"> </script>
</head>
<body onLoad="initialise()"> Hello </body>
</html>
subpage.js
function initialise() {
alert("Script loaded.");
}
Thanks for looking.
Turns out its just a security exception
Unsafe JavaScript attempt to access frame
with URL file:///C:/Users/.../website/index.html
from frame
with URL file:///C:/Users/.../website/subfolder/subpage.html.
Domains, protocols and ports must match.
Once its online it should be fine.
Is it possible to change firefox bidi numeral by javascript? I need it to display numbers in a report created by PHP.
From a normal web page, no.
Here is an old article about saving an html file in the mozilla RES folder that may still work
http://forums.mozillazine.org/viewtopic.php?f=7&t=87755
Make a file in your Firefox installation folder, under the res directory, called for example 'bidi.htm',
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Bidi Toggle</title>
<script type="text/javascript">
// <![CDATA[
function loaded() {
netscape.security.PrivilegeManager
.enablePrivilege("UniversalBrowserAccess UniversalXPConnect");
var prefs = Components.classes["#mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);
if (prefs.getIntPref("bidi.numeral") == 3) {
prefs.setIntPref("bidi.numeral", 4);
}
else {
prefs.setIntPref("bidi.numeral", 3);
}
self.close();
};
self.onload = loaded;
// ]]>
</script>
</head>
<body>
Please wait...
</body>
</html>
and have a bookmarklet
javascript: void(window.open('resource:///res/bidi.htm'));
Need help with my simple script that is supposed to auto click next after 5 seconds.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>
</title>
<script type="text/javascript">
window.onload = Next() {
setTimeout(Next() {
var next = document.getElementById("NEXT");
window.location.href = next.href;
}, 5000);
}
</script>
</head>
<body>
<div align="right">
<a id="NEXT" href="http://www.mysite.com/pictures.php?id=34">[ NEXT ]</a>
</div>
</body>
</html>
Your problem is that .click() only works on buttons.
Whilst were at it lets use unobtrusive javascript.
window.onload = function() {
setTimeout(function() {
var next = document.getElementById("NEXT")
window.location.href = next.href;
}, 5000);
}
Live example.
Edit
window.onload = Next() {
setTimeout(Next() {
Don't use the word Next() just use function()
To create functions you need either function () or function SomeName()
On a point of correctness, your script doesn't say it's javascript (you need to say which scripting language it is), and your html technically doesn't say it's HTML (it's missing a doctype declaration):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Title of the document</title>
<script type="text/javascript">
function next() {
// '1' dynamically generated when this page was generated by PHP,
// and will be '2' next time the page loads.
location = "pictures.php?id=1";
}
document.addEventListener("DOMContentLoaded", function(){setTimeout(next,5000);}, false);
</script>
</head>
<body>
...
</body>
</html>
This sounds like being pedantic, but IE in particular is really anal about having those things. Without a doctype declaration, it won't treat a document starting with as HTML code, but start to take fairly inaccurate guesses.