I want to send the actual page by email, i can send it the problem is that when i open the mail the html dont have the css is obviously but how i can make that look seems the browser?
First I set in a hiddein input the html of the page:
var codigo = $("body").html();
$("#codigohtml").val(codigo);
And then i take it by selector .val() and put this in the message of the email i put the type of the mail to html.. the problem is with the css.
Thanks for your time!
Rather than having a separate CSS stylesheet, just put your CSS directly in your head tag:
<head>
<style>
/* CSS goes here */
</style>
</head>
<body>
<!-- Rest of email -->
</body>
Related
I put a php form into my html file, changed the file from index.html to index.php. Website is loading, form is working. However Website loads first where the form Begins and not at the Header. Is there any command how I can force the Website to load at the Header first?
Thanky, appreciate any help!
It sounds like your PHP code is at the top of the page.
Is your page structured like
<?php
form
?>
<html>
<head>
If so, you need to move the PHP code down in to the main body section where you want the form to appear.
<html>
<head>
head stuff
</head>
<body>
fjdkdfjkfdj
dfkjkjfljfdk
<?php>
form
</php?
fjdkfdjd
footer text
</bod>
</html>
I'm trying to use the following code to replace <body> tag from page with <body id="khanqah">
echo str_replace("%body%", "khanqah", "<body id='%body%'>");
It does adds <body id="khanqah"> to the page but the actual <body> tag still presents. I mean there are two body tags now, one <body> and the other <body id="khanqah">
Also the <body id="khanqah"> tag is adding at the top of page, see this: http://i.imgur.com/6zYWTv8.jpg (screenshot of page source)
Is there any way I can work around?
It's not really replacing anything in the HTML, it's just echoing the return value of str_replace("%body%", "khanqah", "<body id='%body%'>") which happens to be the string <body id="khanqah">.
You can only replace the HTML's body element with PHP if you are outputting the HTML with PHP (changing it before outputting it). PHP works server-side, so once the HTML reaches the client it cannot modify it.
You can use JavaScript, which works client-side, to do this.
To change the id of the body dynamically using jQuery (which is the easiest way), you can do
$('body').attr('id', 'khanqah');
Is there a way to inject/append CSS pasted into a textarea into the head section of the page? I'm making the settings page for an app, and I want to allow themes and the option to change minor things by just adding CSS into a textarea then clicking save.
Other option: Is it posiible to have the textarea display a file called "theme.css" then any changes made will be saved as that file. And to completely change the theme, just copy/paste a new one directly into the text box.
If you use jquery this is how you can do
<script>
$("head").append("<style>body {background:blue;}</style>");
</script>
As another option
you can read theme.css file using fread , show it in textarea and save it to file using fwrite.
Something like that?
<!doctype html>
<html>
<head>
<script type='text/javascript'>
function addStyle(css){
var stl = document.createElement('style');
stl.innerHTML = css;
document.getElementsByTagName('head')[0].appendChild(stl);
}
</script>
</head>
<body>
<p>Paragraph To Test<p>
<textarea id="txtarea">p{color:red;}</textarea>
<input type="button" value="Set Style" onclick="addStyle(txtarea.value);">
</body>
</html>
Is it "okay" to have an HTML document embedded inside the body tag of another HTML document?
The reason why I want to do this is so that I can call a javascript body onload -- I cannot do that in the main HTML document because the main HTML code is dynamically generated by a controller (Yii) that controls other pages and I do not want to edit it.
*By the way, I tried it and it seems to work fine now, but I just want to be sure that the page will not break in the future for whatever reason.
<html>
<head>
<body>
<html>
<head>
<script type="text/javascript>
function somefunction(){
}
</script>
</head>
<body onload="javascript:somefunction()">
</body>
</html>
</body>
</html>
If all you want to do is attach an onload event, you're going about it the wrong way.
All you have to do is add a script element that attaches an onload event:
<script type="text/javascript">
function somefunction()
{
...do stuff...
}
document.body.onload = somefunction;
</script>
Alternatively, if you've appended your JS files at the bottom of the page, they will be able to interact with the DOM similarly to how onload works. The reason to use onload is only so that the elements defined within the web page have been added to the DOM by the time a function is executed. If your scripts are after your content, the elements will be in the DOM.
No, that's bad HTML.
Just put your JavaScript at the bottom before </body>.
I am trying to display a "preview" of an HTML email. I have the HTML in my database and now I need to render it in an iframe, or popup window or something. I am trying to inject the html into a div tag on the page, but it won't display anything. Here is the problem I am running into (I have nested HTML tags):
<html>
<body>
<h1>My page</h1>
<div id="email-body">
<html>
<body>
<p>email</p>
</body>
</html>
</div>
</body>
</html>
You can write HTML to a popup window.
var preview = window.open("", /* options */);
preview.document.write(html);
preview.document.close();
But like me, many dislike popup windows. Another consideration is to just display only the <body> contents. Even better, most mail clients just supports it. With a content type of text/html, you can send a HTML mail as if it is going to be part of a HTML <body>.
<p>email</p>
This way you can for preview just inject it in some div in the main page the usual way.
If you like to style elements, but dislike inline styles, you can also add <style> element. Most of those mail clients also just supports it.
<style>p { font-family: arial, sans-serif; }</style>
<p>email</p>
From HTML purist's view this is indeed syntactically invalid. But it works (also in webbrowsers!) and eases the stuff a lot up.
Assuming that the markup looks exactly like you showed in your post, you could just strip the tags out like this (run this on the email field after you get it from your db):
$email = preg_replace('/\<\/?(html|body)\>/', '', $email);
This will leave you just the body content of the email. This will work as long as the email doesn't have anything in between <html> and <body>, such as a <head> section.
That won't work because you can't have two HTML structures in a document.
The only way to do this that I can see is using an iframe.