#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    288
    Rep Power
    12

    Including javascript in a window created by javascript...


    Ok seems simple to me, but I don't know JavaScript all that well yet.

    I have a very simple script setup to open an image in a new window, the image url, new window title, width and height are all generated dynamically within the onclick part of the link by PHP.

    For the new window, which contains the image, I want to disable right click (again simple, and yes I know it's not a perfect solution but it stops petty theives at least), however as the JavaScript in the main document is writing all the HTML (including - hopefully - the JavaScript) in the new document this is where it goes a little wrong.

    I've tried a couple of attempts at trying to figure it out, but I either get no effect at all, or parts of the JavaScript displaying in the main document.


    Here's the lines that are causeing me problems - I've removed most of the script as it's all just basic document.write's:

    Code:
    <SCRIPT language="JavaScript">
      function display_image(title, img, width, height) {
        View = window.open "", "Preview", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,width=" + width + ",height=" + height);
        View.document.open();
        View.document.write("<HTML><HEAD>");
        View.document.write("<TITLE>"+ title +"</TITLE>");
        View.document.write("<SCRIPT LANGUAGE=JavaScript SRC='data/right_disable.js' TYPE='text/javascript'></SCRIPT>");
    
    etc...
    Any ideas

    -D
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    288
    Rep Power
    12
    Ah-ha...

    I realised that the closing </script> tag that the original script was supposed to be outputting in the newly created page was causing the browser to think that it was the closing script tag of the original script.

    Fix:
    Code:
    View.document.write("<SCRIPT LANGUAGE=JavaScript SRC='data/right_disable.js' TYPE='text/javascript'></SCR" + "IPT>");
    Sneeky huh?

    -D

IMN logo majestic logo threadwatch logo seochat tools logo