In one of my previous post, we have already discussed about how to create an HTML iFrame in order to embed any document or a webpage to your website or blog. An inline iFrame is used to embed another documents or web pages within the current document. If you’re familiar with basic HTML, It will be easier for you to create an iFrame but if you’re not, then you do not need to worry as we have already provided an iFrame Generator tool that will help you to create an iFrame and customize it according to your requirements even you don’t know much more about HTML language.

Prevent embedding website inside iframe

Now, let’s move to today’s an another post i am going to share is that how you can prevent embedding your website or blog inside an iFrame. There are many websites on the web that will embed your website content using iFrame. In case if you don’t want people to do that you can prevent it using a snippet code of JavaScript. This javascript code will help you to stop your page being framed by someone else by redirecting the page embedding your page to your page only.

Also see : How to Disable CTRL+U, CTRL+C and Right Click on a Webpage

All you have to do is paste below javascript code before </head> or </body> tag in your blog or website’s HTML.

<script type="text/javascript">
function noiFrame() {
try {
if (window.top !== window.self) {
document.write = "";
window.top.location = window.self.location;
setTimeout(function() {
document.body.innerHTML = '';
}, 0);
window.self.onload = function() {
document.body.innerHTML = '';
};
}
} catch (err) {
}
}
noiFrame();
</script>