I have a controller that is returning a pdf file, this is temporary save in a local folder. It is possible to open a print dialog directly with out open the pdf file using javascript??
public ActionResult LoadDownloadAndPrint(string Download)
{ return File(System.IO.File.ReadAllBytes(target);)
The file is saved in C:\Windows\Temp\3ac416b7-7120-4169-bc4d-61e105ec197c\output.pdf
I've have tried to used embed tag like in this thread Print PDF directly from JavaScript but did not work I guess because is a local place where the file is stored.
After a lot of researching finally get it using iframe. This code was very helpful http://www.sitepoint.com/load-pdf-iframe-call-print/
I have an empty hidden iframe in my view.
This is working in Chrome, FF, but not in IE
Search.openPrintDialog = function () {
var printJobIds = $("input:checkbox[name='Print']:checked").map(function () { return this.value; }).get().join(',');
if (printJobIds.length > 0)
{
JSUtil.BlockUI();
print('/' + JSUtil.GetWebSiteName() + '/Search/LoadDownloadAndPrint?Print=' + printJobIds)
}
return false;
}
function print(url) {
var _this = this,
iframeId = 'iframeprint',
$iframe = $('iframe#iframeprint');
$iframe.attr('src', url);
$iframe.load(function () {
_this.callPrint(iframeId);
});
}
//initiates print once content has been loaded into iframe
function callPrint(iframeId) {
var PDF = document.getElementById(iframeId);
PDF.focus();
PDF.contentWindow.print();
JSUtil.UnBlockUI();
}
Related
I am using casperJS to get links when clicking a button. The links are returned with window.open in javaScript.
The code I have written logs all the pages after clicking button, but phantom is not exiting in terminal window. Also some pages only show about:blank, especially the last ones.
var casper = require('casper').create();
var page = require('webpage').create();
var address = 'http://www.example.com';
page.open(address, function() {
page.onPageCreated = function(newPage) {
newPage.onClosing = function(closingPage) {
console.log('A child page is closing: ' + closingPage.url);
/* if i set phantom.exit() it will only log the first page url.
Problem: I need all page urls. */
}
}
page.evaluate(function() {
$(".button").click();
});
}
The method "getCurrentUrl()" will return the current url. Here is an easy (not really meaningful) example:
casper.test.begin('My Test', 1 , function suite(test) {
casper.start().viewport(1600,1000).thenOpen("https://blabla.de", function() {
var mylink = this.getElementInfo("#linkid").text;
this.clickLabel(mylink);
});
casper.waitForSelector("#page2", function() {
this.echo(this.getCurrentUrl());
});
casper.run(function() {
test.done();
});
});
You can get the URL of the current page in CasperJS using one of the following methods:
casper.getCurrentUrl():
Retrieves the current page URL. Note that the URL will be URL-decoded.
casper.page.url:
Accesses the existing PhantomJS WebPage instance (page), and gets the current URL of the web page.
casper.evaluate(function () { return location.href; }):
Evaluates the page URL in the Page DOM Environment.
I have a WinJS project and I receive toasts notification from my webservice. In my webservice my XML is like:
string type = "Computer";
string toast1 = "<?xml version=\"1.0\" encoding=\"utf-8\"?> ";
string message = "{\"Message\":{\"Id\":\"6724d22a-87fe-4137-b501-9d9a9a0558b1\",\"DetailId\":\"dc02e784-7832-4625-a538-29be7f885ccb\",\"Description\":\" Message\",\"UserName\":null,\"ActionDateTime\":\"2015-09-15T15:36:14+05:45\",\"CalamityId\":\"c0fa848e-ee6c-4b91-8391-a12058f25387\",\"UseConferenceCalls\":true,\"IsActionCompleted\":false},\"Type\":\"COmp\"}";
string toast2 = string.Format(#"<toast launch= '{0}'>
<visual version='1'>
<binding template='ToastText04'>
<text id='1'>{1}</text>
<text id='2'>{2}</text>
</binding>
</visual>
</toast>", message, "Alert", type);
string xml = toast1 + toast2;
I want to navigate to a specific html page with the useful json as parameters when user click on toasts. Please suggest me some ways to do this.
Currently I have implemented the following function to handle my toasts.This only works when the app is in active state i.e. running in foreground or background. But when the app is closed completely this function won't hit and failed to meet my requirement.
WinJS.Application.addEventListener("activated", onActivatedHandler, true);
function onActivatedHandler(args) {
if (args.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
var messageDetails = (args.detail.arguments).replace(/\\/g, '');
PhonegapService.setNotificationMessage(messageDetails, function () {
window.location.href = "page3.html";
});
}
}
I was facing a similar issue. In my case I was calling functions even before cordova deviceready was fired. From your question not sure if yours is a cordova app or not but make sure all the required javascript files are loaded. You can execute your logic once document is ready. I assume you are using jquery.
function onActivatedHandler(args) {
if (args.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
$(document).ready(function(){
var messageDetails = (args.detail.arguments).replace(/\\/g, '');
PhonegapService.setNotificationMessage(messageDetails, function () {
window.location.href = "page3.html";
});
});
}
}
From my jsp, triggering a servlet request using window.open(url) that will return an ms-office file . After doing some action(open,save or close), the jsp should close automatically .
w = window.open(url, "_self");
$('#choiceSelection').html('<br><br><br><center><div id="reportContainer" class="reportContainer"><img src="loadingAnimation.gif"></div></center>');
//get the child window document loading status
statusX = w.document.readyState;
chk_timer = setTimeout("chk_popup_loaded()", 1000);
//alert(statusX);
//window.close();
}
function chk_popup_loaded() {
//alert("aaa");
statusX = w.document.readyState;
alert(statusX);
if (statusX != "complete") {
chk_timer = setTimeout("chk_popup_loaded()", 1000);
} else {
clearTimeout(chk_timer);
w.close();
}
if (statusX == "interactive") {
//alert("interactive");
//w.close();
window.close();
}
}
Is there any alternative to achieve this? The servlet will give response as ms office format file , it will download automatically to prompt us for save or open options. If I open that file current jsp file should close.
I've achieved this in IE8 using readystate but this feature is not available in IE11. How can I achieve this ?
I'm currently working on a project using jQuery and Ajax to load in content from local html files to my single page site. I've also got a JSON file that I'm trying to incorporate into the files being loaded in with jQuery and Ajax.
I'm using hash urls to keep the pages separate. This is the code I'm using:
//other cached links
var pageLinks = $(".pageLink");
if(window.location.hash) {
var hash = window.location.hash.replace("#", "");
loadPage(hash + ".html");
} else {
loadPage("index.html");
}
pageLinks
.click(function(){
var iid = $(this).attr("id");
loadPage(iid + ".html");
});
function loadPage(resource) {
window.location.hash = resource.replace(".html", "");
$.get("pages/" + resource, function (data) {
content.html(data);
});
}
//this makes sure the contents of hash in the url is loaded in the page
if(window.location.hash) {
var hash = window.location.hash.replace("#", "");
loadPage(hash + ".html");
} else {
loadPage("index.html");
}
This is how I'm putting my JSON data into the page:
function FooBar() {
this.foo;
this.barLinkTemplate;
}
var fooBar = new FooBar();
$(document).ready(function (){
fooBar.contentDiv = $("#fooContent");
fooBar.barDiv = $("#bars");
$.when(
$.getJSON('data/music.json'),
$.ajax('components/components.html')
).done( function(data, templateData) {
var templateHTML = $(templateData[0]);
fooBar.barLinkTemplate = Handlebars.compile( templateHTML.find("#barLinks").html() );
fooBar.data = data[0].foo;
fooBar.barDiv.html( fooBar.barLinkTemplate( data[0].bars ));
));
});
The Ajax loads just fine, hashes and all. However, nothing from my JSON file is loaded into the page. I think I've narrowed my problem down (at least I hope) to one bit of code. If I comment out the last if/else statement (above), the JSON is loaded in the first page (only the first page). If I click on any link, and I navigate back to that page, the JSON data is gone. I have to actually reload the page for the data to reappear.
Without that if/else statement, I lose the ability to load the page content from the hash in the url--though the links still work fine.
I've been googling, but I haven't seen anything similar to the problems I'm having. Any help is appreciated. Thanks!
my process is when user click button print in first form then process is redirect to second page. Now when second page is showed i want to call jquery .How can i do , Please help. because i want to get html from second page.
this is my code in web
<script>
$(function () {
setTimeout(function () { printForm() }, 3500);
function printForm() {
window.onload(function () {
<%testMethod();%>
});
}
});
</script>
this is my code in code behide
public void testMethod() {
if (!Page.IsPostBack)
{
WebClient MyWebClient = new WebClient();
string html = MyWebClient.DownloadString(Session["url"].ToString());
}
}
But the problem is testMethod is calling before scond page is show. i want to do like window.print()
If I understand you correctly, you want to get jquery when other page loads, to do that with js only, you have to do something like this:
your_server ="some_server_name"
(function() {
var jquery_scrpt = document.createElement('script'); jquery_scrpt.type = 'text/javascript'; jquery_scrpt.async = true;
jquery_scrpt.src = 'https://' + your_server + '//code.jquery.com/jquery-1.11.2.min.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(jquery_scrpt);
})();
this will add jquery dynamically to your page.Hope that helps.