1

I have a purchase success page that has an anchor to show the invoice as a PDF such as

<a href="link" id="anchorId" target="targetId" style="display: none;">Click</a>

That purchase invoice has to be opened automatically, so I did like below:

<script type="text/javascript">
    $(document).ready(function () {
        $('#anchorId')[0].click();
    });
</script>

But browsers are not showing the new tab indicating this as a popup. I haven't used window.open so as not to have this kind of browser behaviour.

Is there anything doable to accomplish my use case?

Philippe Gioseffi
  • 1,058
  • 3
  • 16
  • 37
  • 1
    Post complete code. `$('#anchorId')[0]` is invalid, since the `id` is unique. – kind user Mar 29 '17 at 23:33
  • Actually, that's the correct way to do it using ``. – Philippe Gioseffi Mar 29 '17 at 23:40
  • Addressing the anchor is not the problem, the full code isn't here. There is no PDF and no loading function here. – Steve Harris Mar 29 '17 at 23:46
  • @SteveHarris, I didn't understand your previous explanations. Actually that's the full code, I just omitted the real link. As I wrote in your answer, if I remove `display: none;` and click it, the invoice is displayed. Why do it automatically is wrong? – Philippe Gioseffi Mar 29 '17 at 23:49
  • Fair enough, I see the "href". The auto-click is considered a popup by definition. Users can click without causing the blocking. – Steve Harris Mar 29 '17 at 23:50
  • My advice is to open the popup from the previous page where they click "Confirm Order". It's easier and ad-block proof. – Miro Mar 29 '17 at 23:57

1 Answers1

0

You're described behavior is a popup by the browser's (and most folk's) definition so no, it is not likely you will find a workaround. If you do it would be considered an "exploit".

Steve Harris
  • 186
  • 1
  • 4
  • If I remove `display: none;` and click it, the invoice is displayed. Why do it automatically is wrong? – Philippe Gioseffi Mar 29 '17 at 23:41
  • 1
    Because that's what a popup is - An automatic new tab. It has to be triggered by a user event such as click/touch/mousedown etc. – Miro Mar 29 '17 at 23:48
  • This appears to be a possible duplicate question with your answer: http://stackoverflow.com/questions/9514698/bypass-popup-blocker-on-window-open-when-jquery-event-preventdefault-is-set – Steve Harris Mar 29 '17 at 23:49