Results 1 to 3 of 3

Thread: JQuery > button > click created link

  1. #1

    Thread Starter
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    JQuery > button > click created link

    Hi again,

    I have this working in Chrome and Firefox (although Firefox blocked direct clicking on a created link - click a span in a link tho...)
    However, Edge/IE(?) runs the JS up to the JQuery trigger... and doesnt run the last bit.

    Code:
    function dlResultos( mimeType ){
    	var al=$("#hiddenlink");
    	var dt = new Date();
    	var filename = ''+dt.getYear()+(dt.getMonth()+1)+dt.getDate()+dt.getHours()+dt.getMinutes()+dt.getSeconds()+"sql.txt";
        var elHtml = "";
    	var obj = document.getElementById("resultoHidden"); 
    	
    	if( obj != null ) {	
    		elHtml = obj.innerHTML;
    		elHtml = elHtml.split("<br>").join("\r\n");
    		elHtml = elHtml.split("&nbsp;").join(" ");
    	}
    	
    	if( elHtml.length>0 ) {
    		if(al.length==0){
    			al = $("<a></a>");
    			al.attr("id","hiddenlink");
    			al.css("display","none");
    			$("#btnDLR").after(al);
    			al.html($("<span></span>").text("test"));
    		}
    		
    		al.attr('download',filename);
    		al.attr('href','data:' + mimeType  +  ';charset=utf-8,' + encodeURIComponent(elHtml));
    		$("#hiddenlink span").trigger('click'); // < problem is here on edge
    
    	}else{
    		alert("Nada para salvar!");
    	}
    
    }
    Does Edge have a security measure to block this type of clicking ?


    Note: running a Java JSP page... for the extra code not JS...

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  2. #2
    Lively Member
    Join Date
    Jan 2020
    Posts
    120

    Re: JQuery > button > click created link

    Hello,@Ecniv

    Please try this code,To JQuery > button > click created link

    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>jQuery Trigger Click on a Link</title>
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script>
    function doSomething(){
        alert("Click event is triggered on the link.");
    }
    $(document).ready(function(){
        $("button").click(function(){
            $("a")[0].click();
        });
    });
    </script>
    </head> 
    <body>
        <p><a href="#skyImage" onclick="doSomething()">Bookmark link to an image</a></p>
        <button type="button">Trigger Click</button>
        <div style="margin-top: 800px;">
            <img src="/examples/images/sky.jpg" id="skyImage" alt="Cloudy Sky">
        </div>
    </body>
    </html>
    I hope this code will be useful for you.
    Thank you

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: JQuery > button > click created link

    Quote Originally Posted by Prahlad View Post
    Hello,@Ecniv

    Please try this code
    If the OP is still waiting for a solution to this issue after nearly four years, I'd be gravely concerned. That's not to say that you should not provide advice, because it may help others who find this thread via a search. I'm not sure that the OP will be trying it though.

Posting Permissions

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



Click Here to Expand Forum to Full Width