I have displayed a pdf in iframe which is in aspx page. I am working on IE6 browser. I use the following html and javascript code.
<iframe id = "frame_singleCheque" src = "../pdf/SingleCheque.pdf" runat = "server" style ="height:400px; width: 750px; overflow:scroll;" />
function printDoc()
{
window.frames['ctl00_contPlcHdrMasterHolder_frame_singleCheque'].focus();
window.frames['ctl00_contPlcHdrMasterHolder_frame_singleCheque'].print();
}
<input type="button" id = "btnCPrint" value = "Print" onclick="javascript:printDoc()" />
If press print button it shows print dialog. but whenever I press print button it doesn't print any thing. It doesn't print event a blank page. How can I print it?
Try this:
function printDoc() {
document.getElementById('frame_singleCheque').focus();
document.getElementById('frame_singleCheque').contentWindow.print();
}
EDIT: Have a look at this as well.
Related
This is client-side HTML. I'm just using HTML for automation.
My initial goal was to open a new window https://live.ipms247.com/login/ and then paste the values in the three login fields. All three fields have ID tags. And I can write to them from the console. For example.
document.getElementById("username").value="sample";
document.getElementById("hotelcode").value="12345";
document.getElementById("password").value="Password";
I wrote a code to copy text from parent window to child window at the click of a button.
My code is on a local file.
<html>
<head>
<script type="text/javascript">
function init()
{
popupWin = window.open('https://live.ipms247.com/login/','popupWin','');
}
function transferText()
{
popupText = popupWin.document.getElementById("username");
parentText = document.getElementById("parentTextBox");
popupText.value = parentText.value
}
</script>
</head>
<body>
<input type="text" id="parentTextBox" onkeyup="transferText();" value="Hello World">
<input type="button" onclick="init();" value="popup window">
<input type="button" onclick="transferText();" value="Transfer Text">
</body>
</html>
However, this does not work, apparently because my code is on a local file and the website is on another domain.
So my only solution to this problem, so far, is to launch the site with onlick and then focus to it. Press Ctrl+Shift+J to open the console and then paste the commands (I have code which copies them to clipboard) and hit enter.
Is there any possibility to launch the new window with the console open and focus on the console?
You can not do this because JavaScript restricts you to the user.
If you want to reach your goal, you can use the frames API
I just began JavaScript and I've been stuck for a few hours now with an onclick which is not working, or maybe it's the document.getElementById. What I want to do is hide the div when I click on it.
If anyone can explain me what I'm doing wrong I would be grateful!
function closing() {
var closecook = document.getElementById("cookies");
closecook.style.display = "none";
}
#cookies{
display: block;
}
<div id="cookies" onclick="closing()">
Our website is using cookies, click here to close this message.
</div>
Here's my relevant HTML markup:
<body>
<div id="cookies" onclick="closing()">
Our website is using cookies, click here to close this message.
</div>
</body>
<script type="text/javascript" src="functions.js"></script>
Thanks.
Place your "script" block at the end of your body, not outside of it!
alter you the function "closing" to something like this:
function closing() {
var closecook = document.getElementById("cookies");
console.log(closecook);
closecook.style.display = "none";
}
In your browser: open the console by hitting "F12" or right-click anywhere in your browser and select "inspect element" then choose "console".
Now execute your function by clicking on the div.
If you see a "null" in the console: the problem comes from "document.getElementById("");".
If you do not see anything pop up in the console, your javascript file is not loaded properly. Make sure there is no typo in the file name! (Linux is case-sensitiv!).
I have a button defined in HTML.
I want to load a page background.html when this button is clicked. But I want to do it from javascript, not from inside the .html file. So on my register.js file I have below:
$(document).ready(function() {
$("#btnApply").click(function() {
window.open("background.html");
})
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" id="btnApply" value="Register">
But this doesn't load the page. What am I missing?
<input type = "button" id = "btnApply" value = "Register" onclick="loadPage()">
then the function could be in your register.js file as :
function loadPage()
{
window.location="background.html";
}
It might be because popups are blocked on that page. All you need is to allow them (a screenshot from Chrome):
And ensure that you:
Run this code in the browser (otherwise you will not have window object)
background.html is in the same folder as your script
The open() method opens a new browser window. If you want it to load from the same window use location object.
window.location.assign("background.html");
I have an iframe like
<iframe id="Frame1" name="Frame1" style="width: 810px;overflow:hidden;height:525px;border:none;"src="templates/template1.html">
</iframe>
When I click generate button
the generate function will call.In generate function i changed the src of the iframe to template2.html.
<input type="button" id="btngenerate" onclick="Generate();"/>
<a id="print" onclick="OnPrint();">Print</a>
When I click on the print link after clicking the generate button,I want to print the iframe.
function generate()
{
var billPath = "templates/template2.html";
$("#Frame1").attr("src", billPath);
}
function onPrint()
{
window.frames["Frame1"].window.focus();
window.frames["Frame1"].window.print();
}
It works in Firefox. But not in chrome.
In chrome the template1.html will be printed.I want to print template2.html.
When I call window.print(); it will print the whole page.
Please help me...
Is it possible for you to use a separate window to print your content (like I described here https://stackoverflow.com/a/23281929/701869) ?
I have a Iframe and I am Displaying the PDF inside the Iframe , Now i have to print the Iframe
Document on clicking the Print Button , Its Working fine with Crome , but not working with IE9
frames[0].focus();
frames[0].print();
I am using this code on javascript on button click , its working with Crome but not IE9.
This is Iframe tag:
<iframe id="myIframe" name= "tabsa" runat="server" src="PDFFilePage.aspx" height="800px" width="100%"></iframe>
Try to put the Print Function int the Iframe Page
and call it from the Parent
in the PDFFilePage.aspx page
function PrintPDF() {
Windows.Print();
}
and in the Parent
frames[0].PrintPDF()