0

I have a small program in JSP which basically when I click on a document, it opens a new window that allows me to view it. The problem here is it would not show the viewer unless I update or install adobe flash player.

I added a hyperlink link where I can easily click on it and it prompts me to "Allow" to view the document which is fine. The hyperlink looks like below:

<a href="https://get.adobe.com/flashplayer" >Enable Flash</a>

<a href="https://get.adobe.com/flashplayer"><img border="0" alt="Enable Flash" src="enable_flash.gif"/></a>

Now, I have to manually click on it, is there a way I can have the hyperlink auto clicked when the pop up windows shows?

I am new to JavaScript and HTML so I figured there is something that I could use like <body onload > .

Edit

This is how my code looks like now:

<body onload="Auto()" > <!--oncontextmenu="return false;"-->

<script>
    function Auto(){
    <a href="https://get.adobe.com/flashplayer" >Enable Flash</a>

        <a href="https://get.adobe.com/flashplayer"><img border="0" alt="Enable Flash" src="enable_flash.gif"/></a>

    }


</script>

Am I doing anything wrong?

halfer
  • 19,824
  • 17
  • 99
  • 186
Daredevil
  • 1,672
  • 3
  • 18
  • 47
  • 2
    So regardless of whether or not I have flash installed, I will get directed to Adobe? – mplungjan Jan 14 '19 at 09:25
  • Actually what happens in my case is I clicked on the hyperlink, a small window on the left asking me to allow or block Flash. If I hit allow, it loads the documents. I just want to auto click the hyperlink rather than me having to click it – Daredevil Jan 14 '19 at 09:26

3 Answers3

0

You can simply use click() method

Add id to anchor element

<a href="https://get.adobe.com/flashplayer" id="myLink" >Enable Flash</a>

Add to your script

 function automateClick() {
    document.getElementById('myLink').click()
 }
 window.addEventListener("load", automateClick);
JO3-W3B-D3V
  • 2,124
  • 11
  • 30
Sahil Raj Thapa
  • 2,353
  • 3
  • 12
  • 23
0

You can do this with as little as one line, if you want to learn more about the approach I've used, then it may be worth your time looking into functions such as querySelector. Once you have the desired element, you can then simply fire the click method like so.

<a href="https://get.adobe.com/flashplayer">Demo</a>
<script type="text/javascript">
  document.querySelector('a[href="https://get.adobe.com/flashplayer"]').click();
</script>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
JO3-W3B-D3V
  • 2,124
  • 11
  • 30
  • So do i need to create my own javascript function? – Daredevil Jan 14 '19 at 09:20
  • @Daredevil no, I included a `setTimeout` function for this demo only, which I've now removed. – JO3-W3B-D3V Jan 14 '19 at 09:21
  • @Daredevil It's probably best to use a script tag? I take it you're new to front end development? – JO3-W3B-D3V Jan 14 '19 at 09:22
  • Yea because `a href` is HTML tag and I can't include that in a ` – Daredevil Jan 14 '19 at 09:23
  • @Daredevil, I think you need to do a little more research into this matter, you can easily do this like I've done above, here's a link to some [docs for the `script` tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script). – JO3-W3B-D3V Jan 14 '19 at 09:26
  • 1
    @Daredevil, please, do more research, it's not possible to write HTML **directly** into a script tag, that'll just throw errors. Look at what I've provided in my answer, do **something** more like that, c'mon dude... – JO3-W3B-D3V Jan 14 '19 at 09:43
0

Yes..you can use below code and load your link there

$(document).ready(function() { 
 document.querySelector('a[href="https://get.adobe.com/flashplayer"]').click(); 
});

OR

$(function() { 
 document.querySelector('a[href="https://get.adobe.com/flashplayer"]').click(); 
});

OR

window.onload = function() {
   document.querySelector('a[href="https://get.adobe.com/flashplayer"]').click();
}
p u
  • 1,395
  • 1
  • 17
  • 30