After downloading a page from the web using HTTP, this Meteor server code using "email 1.1.16 package" sends that page over to my email successfully but I receive the row html string.
It is a report which I wish to view and maybe print, it would be nice if it is a pdf attachment so that I can just click to open it, or be able to view the page in a different tab.
how can I go about fixing this problem? Thanks
Email.send({
to: "abc#xyz.com",
from: "aaa#bbb.com",
subject: "My report",
text: rowHtml
});
edit
After ready Vasil's answer, the Blaze.toHTML "Renders a template or View to a string of HTML".
But I already have a html string, why do I need to convert it to html string again?.
var html = Blaze.toHTML(Blaze.With(data, function() { return Template.my_template; }));
Email.send({
to: "abc#xyz.com",
from: "aaa#bbb.com",
subject: "My report",
text: html
});
Using dynamic HTML templates in Meteor emails
All what I had to do is to change the line text: rowHtml to html: rowHtml according to the docs
Email.send({
to: "abc#xyz.com",
from: "aaa#bbb.com",
subject: "My report",
html: rowHtml
});
Related
I'm practicing pure node js and i've encountred a thing that disturb about http protocole.
I finally served my html page with css after an hour or so of searching and testing my code. Here is my code :
const server = http.createServer((req, res)=>{
if(req.url === "/"){
fs.readFile("index.html", "UTF-8", function(err, data){
res.writeHead(200, {"Content-Type": "text/html"});
res.end(data);
});
}else if(req.url === "/styles.css")){
var cssPath = path.join(__dirname, 'public', req.url);
var fileStream = fs.createReadStream(cssPath, "UTF-8");
res.writeHead(200, {"Content-Type": "text/css"});
fileStream.pipe(res);
};
});
But I didn't understand why it works. Well I've only typed "/" in the browser, I didn't type "/styles.css". And why I don't see "/styles.css" in the URL bar.
I'm sure it's because of how the http protocole is designed but can you help with some explanation of this protocole.
Thank you in advance.
If you had typed /styles.css in the address bar, then you would see the source code the CSS file. For example: this link.
You type /, then the browser asks the server to / and the server responds with an HTML document.
Then the browser renders the HTML document. The HTML document, I assume, includes something like:
<link rel=stylesheet href=/styles.css>
So the browser asks the server for /styles.css and the server responds with a CSS file. The browser then applies that CSS to the HTML document.
It doesn't show /styles.css in the address bar because you are looking at /. The CSS file is just a different resource that is needed to fully render the HTML document that / represents.
Possible duplicate question
Prior to asking this, I did some searching and found this question that is similar by name, but I don't understand if it's what I need:
Chrome Extension: how to capture selected text and send to a web service
Especially Mohamed Mansour's answer looked promising, but after spending over an hour researching, experimenting and testing, I still don't understand it. So I hope this possibly duplicate question will at least help other people with the same confusion that I have.
Question
Besides the title of this question, I'll include some details of what I want to do:
Select text on any website
Right-click to open the context menu of my chrome extension
Send that text to my website's database.
But for testing purposes, I thought I would replace the third point with sending a basic post-request to a site like hurl.it
So how do I send such a post-request from my chrome extension to a specific external website?
I already know how to get the selected text:
manifest.json
{
"manifest_version": 2,
"name": "My Plugin",
"description": "Test extension",
"version": "0.1.20150917",
"permissions": [
"contextMenus"
],
"background": {
"scripts": ["script.js"]
}
}
script.js
function handleSelectedText(info,tab) {
var selectedText = info.selectionText;
console.log("Selected text: " + selectedText;
//This where I thought I'd send the data to my domain
//And some pseudo-code to show how I thought it would work:
/*
chrome.extension.postRequest(selectedText, function(response) {
if(response == success)
displayNotification("Yay, it worked!");
else
displayNotification("Error: " + response.errorMessage);
});
*/
}
chrome.contextMenus.create({
title: "Mark error: '%s'",
contexts:["selection"],
id: "cc-mark",
onclick: handleSelectedText,
});
If I insert Mohamed Mansour's code into mine, I just get an error saying that response is undefined, so I'm assuming I'm doing that so terribly wrong that I shouldn't even include it.
If it isn't obvious already, I should mention that I'm new to Chrome extensions.
I'm trying to fire a chrome notification ( in a chrome extension ) with the following code:
var opt = {
type: "basic",
title: "Deploy",
message: "It worked!",
iconUrl: "test.png"
};
chrome.notifications.create("", opt, function(id) {
//console.error(chrome.runtime.lastError);
});
But it shows me the following message :
"Unchecked runtime.lastError while running notifications.create: Unable to successfully use the provided image. "
My image "test.png" is in the root folder of my app( with the manifest.json file ), but I've tried to put the picture also in other folder of my app, it never worked!
I've correctly added the permission for notifications, so I really don't know where the problem is !
Any ideas ?
Thank you,
EDIT: I found the solution ! The image needed to be 80*80 !
I am trying to extract a videolink from a streaming website.
So I use PHP and "file_get_contents" to open the videolink and then "explode" to find the link to the generated link
Its looks like config5/videoid/generatedhash/ but you can access it also with config5/videoid/
So when I open this link I see this:
document.write('<div id="mediaspace2" style="width:880px;height:495px">');
jwplayer.key="key";
document.write('<div id="mediaspace" itemprop="video"></div>');
var scrwid=window.screen.width;
var def=false;
if(scrwid<1200) def=true;
jwplayer("mediaspace").setup({
sources: [{
file: "http://linkto.mp4",
label: "1080p HD",
type: "mp4"
}
,{
file: "http://linkto.mp4",
label: "720p HD",
type: "mp4",
} ,{
file: "http://linkto.mp4",
label: "360p",
type: "mp4",
"default": def
}
and a lot more stuff
when i copy one link of my choice and open it in chrome everything is fine. but when i try to embed it with html5 video tags it opens a file named na.flv
ist like a security for the website
how can i decrypt it? :/
I'm trying to get my page Data.aspx to return an html table, but I want that table to be in an excel format. This is my code so far.
In the Data.aspx Load:
Response.Clear()
Select Case lstrCmd
Case "summary"
Response.Write(Summary())
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Case "export"
Response.ContentType = "application/ms-excel"
Response.AddHeader("Content-Disposition", "attachment;filename=" & _
mstrProjectName & ".xls")
Response.Write(SummaryExport())
End Select
Response.End()
So the add header is where I'm puzzled. This is something another peice of my software uses, but I'm not sure if it will work..
the jquery that calls this is using ajax:
function btnSubmitExport_Click() {
var compID = $("#ddlCompanies").val();
var projectID = $("#ddlProjects").val();
var startDate = $("#txtStartDate").val();
var endDate = $("#txtEndDate").val();
var compName = $("#ddlCompanies :selected").text();
var projectName = $("#ddlProjects :selected").text();
$("#content").html("<div class='loading'>loading...</div>");
$.ajax({
url: "Data.aspx",
data: {
CompanyID: compID,
ProjectID: projectID,
CompanyName: compName,
ProjectName: projectName,
StartDate: startDate,
EndDate: endDate,
Cmd: "export"
},
success: function(html) {
$("#content").html(html);
},
error: function(response) {
alert(response);
}
});
}
So, typically, when I request this data, I just throw the resulting html into a "content" div on my default.aspx page.. but I want that html to be an excel file!
Any hints or thoughts on this would be helpful.
I see the same question in other places, but not any answers that help me with my existing code..
If you have an html text contains Table tag in it, simple save it with extension of XLS and Microsoft Excel will open it like a charm! And also as I've seen, you want user to download the file, not to show its content in the page. You should redirect page on your ASPX page directly (without using JQuery). I'd suggest you to use network monitor in the developer tools to see what's happening.
Cheers
Normaly you would need to use this header
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "filename=excelfile.xls"
Print all the output as you want it in this specific page and that would be it.
Research on these headers and you will be fine.