Results 1 to 2 of 2

Thread: Javascript Image Preview

  1. #1
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default Javascript Image Preview

    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

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <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>
    <script>
    var enter = false;
    $(document).on({
      mouseenter:function(){
       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){
        	$('body').append(app);
          
        } $('#preview>iframe').attr('src',srcx);
       $('#preview>iframe').load(function(){
         $(this).parent().children('img').css('display','none');
         $(this).fadeIn(200);
       });
      },
      mousemove:function(e){    $('#preview').css('left',e.pageX+10+'px');
                            $('#preview').css('top',e.pageY+10+'px');
      },
      mouseleave:function(){
      	$("#preview").remove();
      }
    },'.box');
    
    function la(x){
    	$('#l').append(x);
    }
    function lt(x){
    	$('#l').text(x);
    }
    </script>
    <style>
    #preview {
      position:absolute;
    }
    #preview>iframe {
      display:none;
    }
    </style>
    </head>
    <body>
      
    <div id=l></div>
      
    <a href="http://thebcelements.com/" target=_blank class=box>
      Checking
    </a>
    <br />
    <a href="http://phpfiddle.org/" target=_blank class=box>
      Two
    </a>
    
    </body>
    </html>
    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)
    Last edited by Deadweight; 02-19-2016 at 05:45 PM.
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. How can I add a hyperlink to the preview image
    By Munders in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 11-06-2011, 03:37 PM
  2. About moving image preview
    By titipoco in forum CSS
    Replies: 4
    Last Post: 01-26-2010, 08:09 PM
  3. Image Hover Preview Help!
    By Cindrine in forum CSS
    Replies: 3
    Last Post: 01-26-2010, 07:57 PM
  4. Replies: 0
    Last Post: 04-02-2009, 01:09 PM
  5. Replies: 0
    Last Post: 04-18-2008, 07:34 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •