I've been working on a project with a feature so that when I click a button, Outlook will open and the corresponding value stored in a variable will be in the in the body of the mail. I've tried the following code:
<html>
<head>
<title>Email This Code Snippet</title>
<script language="javascript">
function TriggerOutlook()
{
var sub = "Hi friend";
var bodycont = "<html><body>welcome</body></html>";
var body = escape(bodycont + String.fromCharCode(13));
window.location.href = "mailto:sakthivela#yahoo.com"
+ "?body=" + body
+ "&subject=" + sub
;
}
</script>
</head>
<body>
<form id="form1">
Email this Codesnippet
<input type="text" name="txtbody" id="txtbody">
</form>
</body>
</html>
But the body of the mail is <html><body>welcome</body></html> in plain text, not HTML. How do I get it formatted as HTML?
You can't. The mailto specification doesn't have that kind of control over the e-mail client invoked by the browser.
Interestingly, your code works for me as-is when Thunderbird is the default system mailer. Apparently Thunderbird is smart enough to notice that the body starts with <html> and switches to HTML-mail mode.
It would seem at first that to convince Outlook to behave similarly, you might try setting the Content-Type header in the email to "text/html". However, I don't see how this is possible using mailto since you do not have control over the headers.
Related
I'm trying to write a Roman Numeral Converter for php practice that has an input page where the user specifies whether their input is Roman or Numeric, writes the input, and hits submit. This info will then be passed via URL to an output page where the actual conversion happens. Everything for the output is done, but I can't test it because I can't figure out how to open the output php file when the user hits submit. When I change the URL to be opened to a site on the web, it works fine, but even without including the parameters to pass through the URL I just can't get it to open another php file via localhost.
The javascript to go to the output is as follows:
<script type="text/javascript">
function goToOutput(){
var newURL = "http://localhost/Code/RomanNumeral/RNEnd.php";
window.open(newURL);
return false;
}
</script>
I'll obviously have to later add the variables to the URL in order to execute the conversion, but I'm currently using RNEnd.php (which just writes "success") instead of the actual file just to test the javascript, and its not working. If I just type that newURL into my browser, it opens fine.
Any suggestions? I'd be happy to answer any clarification questions if I wasn't clear.
Thanks
whole code as requested for this specific file is here:
<html>
<head>
<link rel="stylesheet" href="RNStyle.css" type="text/css" media="screen"/>
<title>ROMAN NUMERAL CONVERTER - INPUT</title>
<script type="text/javascript">
function goToOutput(){
var newURL = "http://localhost/Code/RomanNumeral/RNEnd.php";
window.open(newURL);
return false;
}
</script>
</head>
<body background="http://upload.wikimedia.org/wikipedia/commons/5/53/Colosseum_in_Rome,_Italy_-_April_2007.jpg">
<div id="RomanNumeralInput">
<h1>ROMAN NUMERAL CONVERTER</h1>
<P>Select your input type and then enter the number.</P>
<form name="convertform" onSubmit="return goToOutput();">
<select name="valuetypes">
<option value="R">ROMAN</option>
<option value="N">NUMERIC</option>
</select>
CONVERT:
<input type="text" name="numcon">
<input type="submit" name="convertSubmit" value="CONVERT">
</form>
</div>
</body>
</html>
If you are using HTML form for SUBMIT, then you should specify the output page url in the onSubmit action.
Else if you are trying to do it through Javascript, I would suggest you use AJAX call to pass the parameters along with URL and get the output of the page and display.
I have a simple HTML page internally which just displays a form and asks the user to fill it out. I want to automatically capture the windows domain username and machine name to submit it together with the data collected in the form.
Can I do that on the client side? HTML? JavaScript? Or am I forced to do it on the server side (which I don't know how to do... yet)
Users have XP and 7 machines and IE7,8.
BTW, I found this article but I have to confess I don't know where in the page you would enter that "code".
Here's the code I'm using that is not working. It calls the JavaScript function, and displays "Username=" and in the next line "Done.", but doesn't display the username.
And if using Chrome, it displays <%HttpContext.Current.User.Identity.Name%>.
<html lang="en">
<head>
<script>
function get_user_Name() {
var username = '<%HttpContext.Current.User.Identity.Name%>';
document.write("Username=");
document.write(username);
document.write(" <br> Done.");
}
</script>
<meta charset="utf-8" />
<title>Training and Development Site</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
</head>
<body>
Add Phone Number to Dialer Do Not Call list
<br><br>
<button type="button" onclick="get_user_Name()">Display User Name</button>
</body>
</html>
Also - I'm using WebMatrix / IIS7 Express
Using only javascript on a none IIS server then it isn't possible.
However:
If you are using IIS then you can use the following JS:
<script language="javascript">
var username = '<%HttpContext.Current.User.Identity.Name %>';
</script>
Assuming you have turned Windows Authentication on in IIS for your site, then C# side:
C#
public string user_Name
{
get
{
string x = Page.User.Identity.Name;
x = x.Replace("YOURDOMAIN\\", "");
return x;
}
}
The x = x.Replace("DOMAIN\\", ""); strips out the DOMAIN sectionof the user acccount e.g NISSAN\rmcdonough
capturing the windows domain username and machine name, I think we can't
It seems that firefox has disabled the ability to run a javascript: from the URL...does anybody know of a way around this?
My site requires an id pulled from the html of another site when that user is logged in. Instead of having the user search the 'view source' page I devised a javascript link to scrape it and send it to the site automagically, but it doesn't work on firefox.
The actual code I'm trying to run:
javascript:void(window.open('http://mysite.com/login?u=' + encodeURIComponent(window.location) + '&s=' + SessionId));
Scrapping the session id from the game in order to pull data for the player, nothing like a facebook hack or anything malicious.
I'd have to see your code but you really shouldn't have a problem doing what you're attempting to do. If you need another option though I have one you could try. If the content of the page you're scraping is within the same domain as your other site you could use an iframe to get the ID.
Here's some code to consider:
Your data collecting page:
<!DOCTYPE html>
<html>
<head>
<title>Disable Firefox 7.0.1 javascript in url security</title>
<script type="text/javascript">
function scrapeData() {
var frame = document.getElementById("otherPage");
var otherPagesObj = frame.contentWindow.document.getElementById("otherContent");
alert("Your data: " + otherPagesObj.innerHTML);
}
</script>
</head>
<body onload="scrapeData();">
<iframe id="otherPage" src="otherpage.htm" width="1" height="1" />
</body>
</html>
Your page to be scraped (otherpage.htm):
<!DOCTYPE html>
<html>
<head>
<title>Other Page - Disable Firefox 7.0.1 javascript in url security</title>
</head>
<body>
<div id="otherContent">1</div>
</body>
</html>
Using the above code you can see "1" alerted from the div of another page. This is a simple, cross-browser compatible option for what you're attempting to do.
Hope this helps.
I have an open web page dialog. From there, what I'd like to do is when the user clicks on a link, refresh the contents of the dialog with modified query string parameters. The problem I am running into is that rather than refresh the same web page with new parameters, a new browser window pops up.
Here is the page used to open the dialog:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
function ShowPopup() {
var popWinFeatures = "dialogWidth: 800px;dialogHeight:600px;center:yes;status:no;scroll:no;resizable:yes;help:no";
window.showModalDialog("webPageDialog.html","PopUpWin",popWinFeatures);
}
</script>
</head>
<body>
Click For Modal
</body>
</html>
and this is the code within the webpage dialog that attempts to refresh the webpage with changed query string parameters:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="scripts/jquery-1.6.4.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
var queryString = "?ab=123";
var newURL = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname;
$('#testLink').attr('href', newURL+queryString);
});
</script>
</head>
<body>
Please Click Me
</body>
</html>
I've also tried using window.open as well as setting window.location. And I've also tried setting window.location.href but the result was the same.
the new browser window displays exactly what I expect. It's just not in the same window.
Thoughts?
Since posting this question, I came up with two possible solutions. In case anyone comes after me and wants to know what I ended up doing, here you go!
The first was just to make the popup non-modal. Removing the modal piece gave me the behavior exactly like I expected it. This didn't work in my situation however for a different reason... It seems that the session cookie was not carried over which in this web app, would cause the log-in page to be displayed before then displaying the correct page. This struck me as odd, but ran out of time to investigate why that was happening.
Second (and this is the solution i ended up going with) was to use an iframe, and display what i needed within the iframe. Definitely not my favorite, but it works!
I'm trying to write a web application using the new offline capabilities of HTML5. In this application, I'd like to be able to edit some HTML—a full document, not a fragment—in a <textarea>, press a button and then populate a new browser window (or <iframe>, haven't decided yet) with the HTML found in the <textarea>. The new content is not persisted anywhere except the local client, so setting the source on the window.open call or the src attribute on an <iframe> is not going to work.
I found the following question on StackOverflow: "Putting HTML from the current page into a new window", which got me part of the way there. It seems this technique works well with fragments, but I was unsuccessful in getting an entirely new HTML document loaded. The strange thing is when I view the DOM in Firebug, I see the new HTML—it just doesn't render.
Is it possible to render a generated HTML document in a new window or <iframe>?
EDIT: Here's a "working" example of how I'm attempting to accomplish this:
<!doctype html>
<html>
<head>
<title>Test new DOM</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
function runonload() {
return $("#newcode")[0].value;
}
$(function() {
$("#runit").click(function() {
w=window.open("");
$(w.document).ready(function() {
$(w.document).html(w.opener.runonload());
});
});
});
</script>
</head>
<body>
<textarea id="newcode">
<!doctype html>
<html>
<head>
<title>New Page Test</title>
</head>
<body>
<h1>Testing 1 2 3</h1>
</body>
</html>
</textarea>
<br/>
<button id="runit">Run it!</button>
</body>
</html>
I think you are overcomplicating this...
try this:
<SCRIPT LANGUAGE="JavaScript">
function displayHTML(form) {
var inf = form.htmlArea.value;
win = window.open(", ", 'popup', 'toolbar = no, status = no'); win.document.write("" + inf + ""); } // </script>
<form>
<textarea name="htmlArea" cols=60 rows=12> </textarea> <br> <input type="button" value=" Preview HTML (New Window)" onclick="displayHTML(this.form)"> </form>
$(w.document).html(w.opener.runonload());
You can't set innerHTML—or, consequently, jQuery's html()—on a Document object itself.
Even if you could, you wouldn't be able to do it using html(), because that parses the given markup in the context of an element (usually <div>) from the current document. The doctype declaration won't fit/work, putting <html>/<body>/etc inside a <div> is invalid, and trying to insert the elements it creates from the current ownerDocument into a different document should give a WRONG_DOCUMENT_ERR DOMException. (Some browsers let you get away with that bit though.)
This is a case where the old-school way is still the best:
w= window.open('', '_blank');
w.document.write($('#newcode').val());
w.document.close();
Whilst you can inject innerHTML into a pop-up's document.documentElement, if you do it that way you don't get the chance to set a <!DOCTYPE>, which means the page is stuck in nasty old Quirks Mode.