Download link using Javascript issue in Opera 9 and Safari 4

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Download link using Javascript issue in Opera 9 and Safari 4

Post by Rovas »

I had "inherited" a JS that displayed a popup div which contained a list of links with "operations" for the file that the user selected.
The original script worked with onmouseleave event and JS DOM script specific for IE. I made a new script to work with Firefox. The problem is that some operations with the new script don' t work in Opera 9.6 and Safari 4 beta.
The script:

Code: Select all

 
//global variables
var dl_string;
var zoom_url;
 
//this function displays the popup div and initiliases the 'operations' functions with their parameters, which are global  
    function ShowDialog (e,param_1,param_2,param_3,param_4,param_5,param_6) {
        zoom_url = param_1;
        zoom_window_name = param_2;
        zoom_window_params = param_3;
        dl_string = param_4;
        admin_permission = param_5;
        file = param_6;
        var color;  
        var x=0;
        var y=0;
             x = e.clientX;
                y = e.clientY;
        
        color = '#000000';
        if (zoom_url == '') color='#ACA899';
        var oDiv = document.getElementById('DialogZoom');
        oDiv.style.color = color;
 
        color = '#000000';
        if (dl_string == '')    color='#ACA899';
        var oDiv = document.getElementById('DialogScarica');    
        oDiv.style.color = color;
 
        var oDiv = document.getElementById('Mydialog');
 
        oDiv.style.position='fixed';
        oDiv.style.left = x +'px';
        oDiv.style.top = y +'px';
        oDiv.style.display = 'block';
        
    }
//one of the non- working operation 
    function DialogDownload() {
        if (dl_string != '') {
            downloadFile(dl_string);
            CloseDialog (e);
        }
        return false;
    }
//closes the popup div when the mouse leaves it
    function CloseDialog (e) {
        //script by Peter-Paul Koch @ http://www.quirksmode.org
        var tg = (window.event) ? e.srcElement : e.target;
        if (tg.nodeName != 'DIV') return;
        var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
        while (reltg != tg && reltg.nodeName != 'BODY'){reltg= reltg.parentNode}
        if (reltg== tg) {return;}
        else{
            var oDiv = document.getElementById('Mydialog');
            oDiv.style.display = 'none';
        }
    }   
 
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Re: Download link using Javascript issue in Opera 9 and Safari 4

Post by Rovas »

I used the Web Inspector and observed that when the user clicks the link in the popup div the download function doesn' t transmit the url to the that file.
Opera blocks the download citing security issues.
Solved it for Safari by changing a different function that permitted the download through an iframe.
Post Reply