I have a page (specifically, a Chrome developer extension) used for debugging client installations of some software. If clients need more help for a specific problem that they are observing, we want them to be able to email us with documentation of the problem.
Is there a way for a mailto to add (as an attachment or a frame within the email body) a file of the current html page the mailto is on? The page is dynamically generated locally, so it would be preferable if the page didn't have to be uploaded anywhere but the email.
Look at this w3schools example: http://www.w3schools.com/html/tryit.asp?filename=tryhtml_links_mailto_subject
(formatted excerpt, you will want the href="" to be all on one line)
<a href="
mailto:someone#example.com?cc=someoneelse#example.com
&bcc=andsomeoneelse#example.com&subject=Summer%20Party
&body=You%20are%20invited%20to%20a%20big%20summer%20party!" target="_top">
Send mail!
</a>
You can use javaScript to insert into the link the page as you need.
EDIT:
Just noticed that you might want to be careful with 'larger' pages, as there is a limit to how long a GET request (which this is) can be: maximum length of HTTP GET request?
tl:dr:
You might want to narrow the scope of what code is included if you use this method
Short answer: No.
The mailto in an a tag is only used to specify a link to an email, not the contents of said email. You would need to use some sort of server-side AJAX call. I would recommending using PHP's mail() function if you can.
Example
You would need to set the email header to be HTML compliant.
So, if you're using the PHP mail() function:
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail("target#something.com", "subject", "PLACE HTML HERE", $headers);
Then you could theoretically just pass off in the AJAX request all of the data from the page:
$.ajax({
url: "http://my.url.com/endpoint/",
method: "POST",
data: {
page: $("html").html()
}
});
Which you would then just embed somewhere in the email, or straight into the body. You could even add extra data for the GET and POST parameters present.
Note
While I can see this being used for some debugging, a lot of errors are caused via Javascript failing in some way or your PHP/server-side code failing. I'd recommend that whatever path you choose, including one I haven't covered, you should also include data from the console, POST, and GET variables if you have access to those (although be careful not to expose the POST and GET variables unnecessarily).
There are also a lot of tools like Chrome Remote Desktop that can help you view specific errors and problems that users are experiencing.
Alternately, to get around the mail() function, you could have embedded debugging Javascript which can dynamically send debugging information from their browser (via an AJAX request) to a server, that intercepts it for you to analyze and debug.
its not possible to include attachments using mailto:
one way to do this is to use mailto: to create a text message with two links:
the page url
the url of a png capture of the page.
there are chrome apis to capture the screen, and you can use your server or something like imgur to save the capture. probably better to use your own server that receives the images as imgur could be a privacy concern for your users.
It seems like a full answer is impossible, but I thought I'd share the route I took.
I have a button with id='save-log'. In the page where I add all the necessary events, I have
document.getElementById('save-log').addEventListener('click',
function(e){
chrome.runtime.sendMessage({
log: document.body.innerHTML
});
}
);
Then in a background page I have
chrome.runtime.onMessage.addListener(
function(message, sender, sendResponse) {
chrome.tabs.create({
url: "save-log.html?" + message.log
});
}
);
And finally, in save-log.html I have the necessary styling information, with an empty body, and run the script:
document.write(decodeURIComponent(location.search.substring(1)));
Now there's a new tab with a full copy of the developer extension panel, and the user can save the html page and send it to whoever they want.
Related
There is a main Sales Page: site.com/sales-page
That page receives visitors from different traffic sources, and they are mentioned on its URL parameters, such as: site.com/sales-page?utm_source=fbads&utm_campaign=banner
That Sales Page has a link pointing to BUY NOW
How do I pass all URL parameters from the current window, such as "?utm_source=fbads&utm_campaign=banner" automatically to the next page via the BUY NOW button?
I need this so the Checkout page will know where the traffic came from, based on that forwarded parameter.
PS: I want to pass all parameters available in the URL, not just pre-defined ones.
PPS: Solution must work on most browsers and on static pages, better to not use cookies/php.
Thanks a lot.
There is no way to achieve this using HTML. You have to use a programming language.
For example:
<?php
$url = "http://example.com/foo/?" . $_SERVER['QUERY_STRING'];
?>
link
If you don't want to use PHP, then other programming languages are available.
There is no way to do it with just html. Best solution is serverside code. Fallback is to use JavaScript, but this will not work if JavaScript is disabled. You can read the search from the url and add it to your link.
<a id="buyNow" href="http://www.example.com">Buy</a>
<script>
(function () {
var lnk = document.getElementById("buyNow");
lnk.href = lnk.href + window.location.search;
}())
</script>
This assumes there is no querystring already on the link. If there is, you need to replace the ? in the search with a &
I try to access and use different pages in NCBI such as
http://www.ncbi.nlm.nih.gov/nuccore/NM_000036
However, when I used perl's LWP::Simple 'get' function, I do not get the same output I get when I save the page manually (with the firefox browser 'save as html' option). What I do get from the 'get' function lacks the data I require.
Am I doing something wrong?
Should I use another tool?
My script is :
use strict;
use warnings;
use LWP::Simple;
my $input_name='GENES.txt';
open (INPUT, $input_name ) || die "unable to open $input_name";
open (OUTPUT,'>', 'Selected_Genes')|| die;
my $line;
while ($line = <INPUT>)
{
chomp $line;
print OUTPUT '>'.$line."\n";
my $URL='http://www.ncbi.nlm.nih.gov/nuccore/'.$line;
#e.g:
#$URL=http://www.ncbi.nlm.nih.gov/nuccore/NM_000036
my $text=gets($URL);
print $text."\n";
$text=~m!\r?\n\r?\s+\/translation="((?:(?:[^"])\r?\n?\r?)*)"!;
print OUTPUT $1."\n";
}
Thanks in advance!
The page at http://www.ncbi.nlm.nih.gov/nuccore/NM_000036 does a lot of JavaScript processing and also loads a bunch of stuff dynamically. LWP::UserAgent does not do that for you as it cannot run JavaScript.
I suggest you take a look at what is happening in your browser, with Firebug or the Chrome Developer Tools. You'll see it does an XHR request to this URL: http://www.ncbi.nlm.nih.gov/sviewer/viewer.fcgi?val=289547499&db=nuccore&dopt=genbank&extrafeat=976&fmt_mask=0&retmode=html&withmarkup=on&log$=seqview&maxdownloadsize=1000000
Now I am not sure how these params translate to the NM_000036, but you should be able to figure that out by looking at some of the JS code that is being run on the page, or trying multiple pages ans looking at the URLs of the XHR calls.
Since this is probably a public service, and I'm assuming you are allowed to take that data, you should consider asking if they have a proper API that you can hit instead of screen scraping the stuff off of their website.
Content you're searching is generated by JavaScript. You need to parse your HTML (from the first response) and find ID for the data you want:
<meta name="ncbi_uidlist" content="289547499" />
Next you need to make another request to the URL in the form: http://www.ncbi.nlm.nih.gov/sviewer/viewer.fcgi?val=ID_YOU_HAVE
Something like this (untested!):
my $URL='http://www.ncbi.nlm.nih.gov/nuccore/'.$line;
my $html=gets($URL);
my ($id) = $html =~m{name="ncbi_uidlist" \s+ content="([^"]+)"}xi;
if ($id) {
$html=gets( "http://www.ncbi.nlm.nih.gov/sviewer/viewer.fcgi?val=" . $id );
$text=~m!\r?\n\r?\s+\/translation="((?:(?:[^"])\r?\n?\r?)*)"!;
print OUTPUT $1."\n";
}
i wonder if there is some way to do something like that:
If im on a specific site i want that some of javascript files to be loaded directly from my computer (f.e. file:///c:/test.js), not from the server.
For that i was thinking if there is a possibility to make an extension which could change HTML code in a response which browser gets right before displaying it. So whole process should look like that:
request is made
browser gets response from server
#response is changed# - this is the part when extension comes in
browser parse changed response and display page with that new response.
It doesnt even have to be a Chrome extension anyway. It should just do the job described above. It can block original file and serve another one (DNS/proxy?) or filter whole HTTP traffic in my computer and replace specific code to another one of matched response.
You can use the WebRequest API to achieve that. For example, you can add a onBeforeRequest listener and redirect some requests:
chrome.webRequest.onBeforeRequest.addListener(function(details)
{
var responseData = "<div>Some text</div>"
return {redirectUrl: "data:text/html," + encodeURIComponent(responseData)};
}, {urls: ["https://www.google.com/"]}, ["blocking"]);
This will display a <div> element with the text "some text" instead of the Google homepage. Note that you can only redirect to URLs that the web server itself is allowed to redirect to. This means that redirecting to file:/// URLs is not possible, and you can only redirect to files inside your extension if these are web accessible. data: and http: URLs work fine however.
In Windows you can use the Proxomitron (proxomitron.info) which is a local proxy that can intercept any page or file being loading into your browser and change it using regular expressions (no DOM parsing) however you want, before it is rendered by the browser.
Suppose I want to embed the latest comic strip of one of my favorite webcomics into my site as a kind of promotion for it. The webcomic has the strip inside of a div with an id, so I figured I can just embed the div in my site, except that I couldn't find any code examples for how to do it (they all show how to embed flash or a whole website).
Can someone please show me (or tell) how it's done?
PS I'd rather not use server side scripting or external services (which is what is often recommended for embedding RSS).
Update - Cross domain request with jQuery (on client side)
Yesterday I was browsing James Padolsey's blog, where he posted a great article, on how to do cross domain request with jQuery, also Chris Heilmann has a nice DEMO.
The principle is to use YQL -> a yahoo api for web page queries, where you receive a JSON with all the html. Happy scraping :)
Scrape remote data with php, load with jQuery
What about considering simple AJAX call, that would intercept the comic element and update with its contents your <div id="update-comic" /> primarily used for this purpose?
Also you will use a simple php to get the remote page, cause you cannot make ajax call on another domain
note: user must have JavaScript enabled, also following code uses jQuery library
Putting it all together
on your page, where you want to display remote comic strip create a div only for this purpose, lets call it update-comic
<div id="update-comic">
<!-- here comes scraped content -->
</div>
write down the php, call it comic-scrape.php, it will download the html from remote page, you should consider caching the response and updating it on a specified interval (e.g. 30min, 1hr, your call.. :))
server performance should not suffer after simple cache checking implementation
<?php
$url = 'http://www.example.com/';
$response = file_get_contents($url);
echo $response;
now comes the jQuery magic, where you make ajax call on your php scraper and take only the relevant element you are interested in. Place this script inside your view page (where you have your <div id="update-comic" />
<script type="text/javascript">
$(function () {
// set all your required variables
var
localUrl = '/comic-scrape.php',
elementId = '#remote-comic-id',
elementToUpdate = $('#update-comic');
// update the local elementToUpdate with elementId contents
// from your php in localUrl
elementToUpdate.load(localUrl + ' ' + elementId;
});
</script>
I hope, I covered everything.
Employing simplexml and xpath
As philfreo suggested in comment, a viable solution could also contain selecting the required id server-side. It is very easy with use of php's simplexml and a little xpath:
<?php
// set remote url and div id to be found
$elementId = 'remote-comic-id';
$url = 'http://www.example.com/';
// instantiate simple xml element and populate from $url
$xml = new SimpleXMLElement($url, null, true);
// find required div by id
$result = $xml->xpath("//div[id={$elementId}]");
// take first element from array, which is our desired div
$div = array_pop($result);
echo $div;
It's impossible because you cannot manipulate iframe/frame content. Using iframe tag will just modify content in tag, but not the src.
Neither with AJAX, because you have to be on the same domain.
So, for example, you can use PHP with cURL or quite simply with fopen.
You can just use an iframe. The content isn't literally on that page, but it looks like it.
Here's an example: http://www.w3schools.com/TAGS/tryit.asp?filename=tryhtml_iframe
It looks like this:
<iframe src ="http://www.example.com/index.html" width="100%" height="300"></iframe>
<embed src="url of your comic" width="300" height="250" />
How do you force a web browser to use POST when getting a url?
Use an HTML form that specifies post as the method:
<form method="post" action="/my/url/">
...
<input type="submit" name="submit" value="Submit using POST" />
</form>
If you had to make it happen as a link (not recommended), you could have an onclick handler dynamically build a form and submit it.
<script type="text/javascript">
function submitAsPost(url) {
var postForm = document.createElement('form');
postForm.action = url;
postForm.method = 'post';
var bodyTag = document.getElementsByTagName('body')[0];
bodyTag.appendChild(postForm);
postForm.submit();
}
</script>
this is my post link
If you need to enforce this on the server side, you should check the HTTP method and if it's not equal to POST, send an HTTP 405 response code (method not allowed) back to the browser and exit. Exactly how you implement that will depend on your programming language/framework, etc.
I have a feeling from your question you were just hoping to send a post request in a browser's address bar.
Just type the following into the address bar swapping the value for 'action' to the url that you like.
data:text/html,<body onload="document.body.firstChild.submit()"><form method="post" action="http://stackoverflow.com">
It's invalid html, but the browser's (at least all the ones i've tested it in so far) know what you mean, and I wanted to keep it as short as I could.
If you want to post values, append as many inputs as you like, swapping name and value in each input for whatever you like.
<input value="hugh.mahn#person.com" name="email">
<input value="passwordsavedinhistory" name="password">
It's important to note that sensitive information you post will be visible in:
your history
your address bar
your browser's autocomplete.
possibly other sites that you visit from the same tab
probably plenty of other things too
It's a really bad way to send a post request, and all the other answers are far better, but it's still cool that you can do it.
<form method="post">
If you're GETting a URL, you're GETting it, not POSTing it. You certainly can't cause a browser to issue a POST request via its location bar.
If you're trying to test something, I'd suggest using Fiddler to craft your http requests. It will allow you to specify the action verb (GET, POST, PUT, DELETE, etc) as well as request contents. If you're trying to test a very specific request from a link but with POST instead, then you can monitor the requests your browser is making and reissue it only with the modified POST action.
you can not force any web browser to send the url with POST header. But to test a POST request url , I can suggest "POSTER" extention of chrome and mozilla
I know this question is old but someone may find this useful. You can use a command line tool like cURL (http://curl.haxx.se/) to post to a URL.
Example:
curl -v --basic --user username:password --request POST "http://www.theurltopostto.com"
The above submitAsPost() function is a good and elegant solution but it has a problem - if the URL is too long some browsers (including Firefox and IE) will return an error. Since many of us use POST in order to bypass this very limitation, I suggest this solution:
// submit a URL using post
function submitAsPost(url) {
var bodyTag = document.getElementsByTagName('body')[0];
var postForm = document.createElement('form');
bodyTag.appendChild(postForm);
postForm.method = 'POST';
var serverAndParams = url.split("?");
postForm.action = serverAndParams[0];
var params = null;
try
{
var paramsAndHash = serverAndParams[1].split("#");
params = paramsAndHash[0];
var attrList = params.split("&");
for (var i = 0; i < attrList.length; i++)
{
try
{
var keyValue = attrList[i].split("=");
var el = document.createElement('input');
el.type="hidden";
el.name=keyValue[0];
var value = keyValue[1];
value = value.replace(/\+/g, ' ');
el.value=decodeURIComponent(value);
postForm.appendChild(el);
}
catch(error){}
}
}
catch(error){}
postForm.submit();
bodyTag.removeChild(postForm);
}
Tested with Firefox, Chrome and IE.
You can use a tool to test. I'm always asking the same question as you. There is quite a few tools available online. Here is the tool that I use: http://www.hurl.it/
This is a little late in the game but I ran across this and found that HTML 5 made some changes. You can use the input tag to add formmethod (thus selecting post). This worked for me.
see : http://www.w3schools.com/tags/att_input_formmethod.asp
If you had the problem of doing:
request.open('POST',url,true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send("data="+JSON.stringify(data));
and in dev tools you still se it is doing a GET then that means that your url is in the following format:
http://example.com/folder
Meaning it should be:
http://example.com/folder/
Its a very bizarre error maybe not related with your question but I ve had it a couple of times and it should be out there as it looks seriously dangerous. This happened to me when using an apache 2 server on Ubuntu 14.04, with not much configuration.
The utility "Fiddler" by Telerik (free ware) allows you to "compose" an http request and send it using any method you choose (Get, Post, Put, Del, etc) It also will give you some very detailed information about the request and the response that can be very helpful during testing and debugging