-
Oct 27th, 2016, 07:41 AM
#1
Thread Starter
Don't Panic!
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(" ").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...
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...
-
Aug 7th, 2020, 02:43 AM
#2
Lively Member
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
-
Aug 7th, 2020, 03:03 AM
#3
Re: JQuery > button > click created link
Originally Posted by Prahlad
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|