-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add check for page's referrer before auto download. #1418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This prevents someone from clicking a Google search result leading to an automatic download that likely is not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for helping us solve this long lasting issue :) a few small comments. Still need to see if there's no problems when running this. Will try to test it ASAP
var ref = document.referrer; | ||
var src = $('#auto-download-link').attr('href'); | ||
|
||
if (ref && src && ref.indexOf(document.location.origin) === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: can you extract the if condition into a method with a clear name please? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm missing your point. But it already is in a method named triggerAutoDownload
. Well, technically, it was in a method I named autoDownload
but then renamed it to the former. If this is not what you meant, please elaborate.
triggerAutoDownload: function() {
var ref = document.referrer;
var src = $('#auto-download-link').attr('href');
if (ref && src && ref.indexOf(document.location.origin) === 0) {
$('.downloading .hide').show();
document.location = src;
}
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe I was not clear, sorry :)
My suggestion was to move the ref && src && ref.indexOf(document.location.origin) === 0
into a method (for instance shouldAutoDownload(ref, src)
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand now. Thanks for clarifying. Change made.
var src = $('#auto-download-link').attr('href'); | ||
|
||
if (ref && src && ref.indexOf(document.location.origin) === 0) { | ||
$('.download .hide').removeClass('hide'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be achieved with $('.download .hide').show()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed per your instruction.
|
||
if (ref && src && ref.indexOf(document.location.origin) === 0) { | ||
$('.download .hide').removeClass('hide'); | ||
$('<iframe frameborder="0" height="1" width="1"></iframe>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems weird. Not an js expert, but there's probably a better way to achieve what you are trying to do in a cleaner way. What are you achieving with this? Will try to see if there's another solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I just took the iframe
markup and included that in the method. Setting the location is a cleaner way to achieve triggering the download.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for taking so much time @mloyd
the code LGTM, but I wasn't able to find a way to test it. Can I ask you how did you do it?
Thanks, @pedrorijo91 and sorry for my late reply. I tested by temporarily changing the <ol>
<li><a href="http://127.0.0.1:5000/download/win">http://127.0.0.1:5000/download/win</a></li>
<li><a href="http://127.0.0.1:5000/download/mac">http://127.0.0.1:5000/download/mac</a></li>
<li><a href="http://localhost:5000/download/win">http://localhost:5000/download/win</a></li>
<li><a href="http://localhost:5000/download/mac">http://localhost:5000/download/mac</a></li>
</ol> Then, after firing up |
This prevents someone from clicking a Google search result leading to an
automatic download that likely is not necessary.