1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to Make Editing a JavaScript as Simple as Possible for my Visitors?

Discussion in 'Programming' started by ccano, Nov 27, 2006.

  1. #1
    Hi,

    I've got a JavaScript file for users on my web site that they have to tweak by inputing their website's address and their affiliate ID.

    I want to make the process of downloading the script as easy as possible for my visitors, so I'm wondering if there's a way for me to have visitors enter their websites and their affiliate IDs in two text boxes on my web page and then when they hit Submit it would output a file that they could download and save on their desktops. That means no manually editing the JS file.

    Can this be done?

    Thanks for your input,
    Chris
     
    ccano, Nov 27, 2006 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Does your host support PHP? If so, post your Javascript code.
     
    nico_swd, Nov 28, 2006 IP
  3. maro

    maro Peon

    Messages:
    356
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That can be easily done using any server side scripting language such as php or asp.
    What does your host support?
     
    maro, Nov 28, 2006 IP
  4. ccano

    ccano Peon

    Messages:
    211
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes my host supports PHP. My code is here http://www.digitalmusictracker.com/featuredmp3player.js

    The ID at the very top is one of the variables I'd want people to be able to change, along with any reference to their site. So anywhere it says www.digitalmusictracker.com my visitors web address would replace it.

    Thanks a lot for your help :)
     
    ccano, Nov 28, 2006 IP
  5. ccano

    ccano Peon

    Messages:
    211
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    My host supports PHP. Does HostGator support ASP?

    Thanks,
    Chris
     
    ccano, Nov 28, 2006 IP
  6. maro

    maro Peon

    Messages:
    356
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #6
    here is a rought script of how it would be implemented.
    First remove the first two lines of your js because they are being generated dynamically from the script and save it somewhere on your server.

    
    <?php
    $filename = "/../pathtoyourjsfile";
    $handle = fopen($filename, "r");
    $contents = fread($handle, filesize($filename));
    $size = filesize($filename);
    fclose($handle);
    
    
    header("Content-type: text/html");
    header("Content-Disposition: attachment; filename=featuredmp3player.js");
    
    
    $modifiedlines = "var affiliate_id= 'digitalmusict-20';\n"."var button_url= 'http://www.digitalmusictracker.com/featuredmp3player-images/buyfromamazon.gif';\n";
    $size += strlen($modifiedlines);
    header("Content-length: ".$size);
    echo $contents;
    ?>
    
    
    Code (markup):
    note that I didn't try the code, so I am not sure if it works correctly. It might need some tweaking
     
    maro, Nov 28, 2006 IP