I have a lightbox plugin that required additional option - print the image.
So I did a little JS function that print that image as follow:
var headstr="<!DOCUMENT html><html xmlns='http://www.w3.org/1999/xhtml'><head><title></title></head><body>";
var footstr="</body>";
var newstr="<img src=\"[img-location]\" alt='courses' />";
document.body.innerHTML=headstr+newstr+footstr;
window.print();
window.location.reload();
The problem is that when the user press on the print button, in chrome it opens a new window (chrome print page) and in it, it says - print preview failed. In firefox and IE8 it works just fine...
I don't know if this is what caused your failure, but if window.print() is called from an <input type="submit"> within a form with method="post" (i.e. every asp.net page ever) then Chrome print preview wigs out.
The solution to this is to add return false; after window.print() so that the page doesn't post back.
<html>
<head>
</head>
<body>
<form method="post" action="test.html">
<p>This is only a test. Had this been a real emergency....</p>
<!--This doesn't work -->
<!-- <input type="submit" onclick="JavaScript:window.print();">-->
<!--But this does -->
<input type="submit" onclick="JavaScript:window.print();return false;">
</form>
</body>
</html>
I'm not sure if this is the problem, but you're creating invalid html. For one, you don't close the <html> tag. In addition, you're putting an html and head tag within your body.
Related
This works just fine in any browser, however, in safari the visibilities don't change until AFTER the file has uploaded or the user hits "stop" in the browser toolbar.
Why oh why is safari the only browser to act this way?
What can I do to fix it?
EDIT: Okay, so I trimmed down my code to just the basic elements, and it STILL acts funny in safari. I cannot figure out what's going on for the life of me. The supplied code is incredibly simplified now... yet, it still refuses to update the visibility options until the file has finished uploading or the send button is pressed without a file in it. Every other browser updates the visibility settings during the upload.
Please, anybody, help!
HTML + JS in head
<html>
<head>
<title>Our Industry Alpha 0.01</title>
<script>
function formcheck() {
document.getElementById('i_submit').style.visibility='hidden';
document.getElementById('patience').style.visibility='visible';
}
</script>
</head>
<body>
<form action="" enctype="multipart/form-data" method="post">
<input type="file" required>
<input type="submit" style="visibility:visible;" value="Send" id="i_submit" onclick="formcheck();">
</form>
<div id="patience" style="visibility:hidden;">... UPLOADING ...</div>
</body>
</html>
I have a button Which prints the Page on click of a button which triggers onclick(); javascript function. the code goes like this.
<html>
<input type="submit" value="Print" onclick="printInfo()">
</html>
Script is placed in <head> tag
<script type="text/javascript">
function printInfo()
{
window.print();
}
</script>
when we click on the button in Chrome and Mozilla the page is printed normally but in IE the font decreases and is set to half of the page.
Please help me on how to maintain consistent in IE and Chrome.
I have a simple HTML code to print the page. Below is the code:
<!DOCTYPE html>
<html>
<head>
<script>
function printPage()
{
var w = window.open("http://www.sigmaaldrich.com/catalog/CofADocRequest.do?symbol=209104&LotNo=MKBP0842V&brandTest=SIGMA","_self");
window.focus();
window.print();
}
</script>
</head>
<body >
<input type="button" onclick="printPage()" value="print a div!" />
</body>
</html>
What the code does is, it displays a button, on clicking that button it calls a function. The function uses open() to open a new URL in the same page by using the “_self ” parameter.
As we can see in the code, the print() is being called after the call to open method. But in my browser IE11, the print pop is being shown befor loading the page.
Due to this I am not printing the correct page.
Can anybody help me on this.
The problem is that window refers to the current window, which is the original.
By opening a new window in self you replace the page, this is basically a redirect.
And if you open it via popup and print it as w.print() than you run into cross-origin security error.
You could use iframe to this with a proxy as shown here
How do print specific content inside the iframe
and
here
How do print specific content inside the iframe
I'm trying to write my first chrome extension to test my acquired knowledge from codecademy (HTML/CSS, JQUERY and Javascript). First of all I'm trying to append text to a paragraph tag via the onclick of a button.
heres my code:
<!doctype html>
<html>
<head>
<title>Facebook event graph</title>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js"></script>
<script src="popup.js"> </script>
</head>
<body>
<form id="inputUrl">
Enter a URL: <input type="text" name="url" id="url">
<button type="button" onclick="getFacebookData()"> Get Data </button>
</form>
<canvas id="graph" width="300" height="100">
</canvas>
<p id="text" width="300" height="100">1</p>
</body>
</html>
and my popup.js:
$(document).ready(function(){
//Variables
function getFacebookData() {
$('p').append('Test');
};
});
it's probably something very basic that I'm doing wrong, but a push in the right direction would be really appreciated :)
You are not allowed to use inline scripting like onclick="getFacebookData()"
You have to remove the handler from html:
<button type="button" id="my-button"> Get Data </button>
And you have to move the handler into popup.js:
$(document).ready(function(){
$('#my-button').click(getFacebookData);
});
You are also, by default, not allowed to load jQuery from an external CDN - and certainly not http one, again for Content Security Policy reasons. And you shouldn't! Put jQuery in your extension's folder and load it locally.
Matter of taste, but I would place getFacebookData() definition outside $(document).ready, so it's available in the global scope. Also, the semicolon after it is not needed.
Last, but not least: for future debugging, inspect the console of the corresponding page of your extension. For things like background/options page you should be able to access them from Developer Mode extensions list. For a popup, you should right-click the button of your extension and select "Inspect Popup".
I have a mother page, where is jvscrpt function called openWin() , which opens a new window.
Here is my code:
<html>
<head>
<script type="text/javascript">
function openWin()
{
win=window.open();
win.document.write("<html>");
win.document.write("<head>");
win.document.write("<style type=\"text/css\">");
win.document.write("#media print{.input {display:none}}");
win.document.write("</style>");
win.document.write("</head>");
win.document.write("<body>");
win.document.write("<table align=\"center\">");
win.document.write("<tr><td>result:</td><td>100,--€</td></tr>");
win.document.write("<tr><td colspan=\"2\" id=\"idcko\"><input type=\"button\" value=\"click\" class=\"input\" onclick=\"window.print();\"/></td></tr>");
win.document.write("</table>");
win.document.write("</body>");
win.document.write("</html>");
}
</script>
</head>
<body>
<form>
<input type="button" value="Click me!" onclick="openWin();" />
</form>
</body>
</html>
When I click on button "Click me!" a new window appears, but browser can`t stop loading the page.The page has full functionality,but for example when I want to see source code in Mozilla, I get only a blank page.
Please help...
call
win.document.close();
At the end(after the last write() )
It signals to the browser that the write-process is finished and the document is complete.
but for example when I want to see
source code in Mozilla, I get only a
blank page.
This is because the source was written by your javascript - this is the same as AJAX (you can't view the changes in the source).
Perhaps you would be better of just opening a new page and pass whatever paramters it needs either via a GET/POST or server-side.