Jquery Print Element...print an external page
The print element plugin does what it says. Prints an element within the current page. However, what I really need to do is print an external page. I DO not want to load that page in an hidden element on the page. I would like t开发者_Go百科o to point the plugin to an external page.
I have actually already created a way to load a page into an hidden element. (below is the code for that). This works ok but causes some other issues and I think it would just be MUCH better to print an external page.
ANY IDEAS?
Here is my current code:
$(".printButton").click(function(){
$("#projectPrint").empty();
$("#projectPrint").load('PRINT_workOrderLastEntered.php', function(){
$('#projectPrint').printElement({
pageTitle:lastProjectNum
});
})
});
You can perform an asynchronous HTTP (Ajax) request Click here. Read about this. Make the ajax request when the print button is clicked , inside the success function you can store the contents of your html file in a variable and then you can print that variable or you can directly access the selectors you need to print, This way you dont have to load the contents of the page.
This is an Example just to show the user how ajax method works. This will have cross domain issues. But still across domains, if the data is only available via RSS and you don't have control of the other domain, then your best option is a server-side proxy.
If you have control over the other domain, you can create a page containing a javascript function which uses XmlHttpRequest to pull the RSS and returns the RSS. Then you can use a cross-domain messaging library like EasyXDM to call that script.
You also might want to check if the RSS feed's website supports JSONP as an alternate format, which would allow you to get the RSS data via javascript. Make sure you trust the site if you do this, though, since the site can execute javascript inside your page!
I have also found Google Feed Apis to be very usefull for cross domain
Sorry for going off topic. Since the user is calling his own local php file he does not have to worry about cross domain issue just by using type = 'GET'; will do. Incase if the data is not being received using the above methods will help!!
$.ajax({
url: 'http://news.bbc.co.uk',
type: 'GET',
success: function(res) {
var headline = $(res.responseText).find('a.tsh').text();
alert(headline);
}
});
I just got parsed an xml ... similarly you can use watever.php instead of bbc.co.uk and in the success function just like what I did you can get the title or what ever you want even contents of a div and save it in the variable eg: headline . You can simply print this variable as it contains the value you seek.
精彩评论