View Full Version : Javascript Image Preview

02-19-2016, 05:37 PM
So I was working on an live website previewer for a website; however, I found out that it is actually extremely bad and you can get attacked very easy (using iframes and what not). Is this true?

Here is the example: http://jsbin.com/busefimahi/1/edit?output

Also, is there a way to prevent redirects. (EG over value two Ill post the code below)
sandbox="" to prevent redirects

<!DOCTYPE html>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
var enter = false;
var srcx = $(this).attr('href');
app = '<div id="preview"><img src="http://www.chimply.com/coconut/images/955666"/><iframe sandbox=""></iframe></div>';
if($('#preview').length === 0){

} $('#preview>iframe').attr('src',srcx);
mousemove:function(e){ $('#preview').css('left',e.pageX+10+'px');

function la(x){
function lt(x){
#preview {
#preview>iframe {

<div id=l></div>

<a href="http://thebcelements.com/" target=_blank class=box>
<br />
<a href="http://phpfiddle.org/" target=_blank class=box>


But my main question is doing a live preview like this a good idea? (I know that https and http websites cant cross and most websites wont work with iframes)

02-20-2016, 04:48 PM
I would say in general no. But I see that the fiddle works. If the pages update a lot, it might be a nice feature for a specific sort of use.

As for sandbox, looks like a good idea for more than just security. It should lower bandwidth as things like flash, other video, audio, etc. will not load. Scripts that force the page in the iframe to the top also will be overridden, as will code that focuses somewhere on the page in the iframe for various reasons (like a form). However you apparently don't need ="" part. <iframe sandbox></iframe> is said to be sufficient. Any values are strictly for exceptions to the full range of restrictions inherent with this attribute when used alone.