+ Start a Discussion
shrey.tyagi88@tcs.comshrey.tyagi88@tcs.com 

Redirect to a page on click of an image on VF page---Please help!!!

Hi All,

       I have an image on my visualforce page (which is rendered as pdf as well). I want that image to redirect me to a link say : google  when it;s clicked. This redirection should also work when the page is rendered as pdf. This is what i have tried so far and itt doesnt work. Request you all to help.

 

    <script type="text/javascript">
    function popupwindow(){
        var newwindow = window.open("http://www.google.com/");
        newwindow.focus();
    }
    </script>

 

<apex:image url="{!$Resource.PDFImage}" onclick="popupwindow" width="550" height="50"/>

 

I  have also tried to use <a></a> tags , just outside <apex:image> but even that doesn't seem to work.

 

Regards

Shrey Tyagi

AnushaAnusha

Hi Shrey,

In PDF script won't work.

do like below,

<apex:image url="{!$Resource.PDFImage}" onclick="window.open('www.google.com');" width="550" height="50"/>

 

This may help you.

shrey.tyagi88@tcs.comshrey.tyagi88@tcs.com

I tried this already , doesn't work. Thanks for your time!!!

AnushaAnusha

do like this then,

 

<apex:image url="{!$Resource.PDFImage}" onclick="window.open('www.google.com');" width="550" height="50"/>

 

<a href="www.google.com" style="height:50px;width:50px;background-image:{!$Resource.PDFImage}" > </a>

SolutionSolution

Hi Shrey,

 

Can you please try this out?

 

<apex:outputLink value="http://www.google.com/" id="CommandLink1"> 
                        <apex:image url="{!$Resource.PDFImage}" width="550" height="50"/> 
</apex:outputLink>
 
shrey.tyagi88@tcs.comshrey.tyagi88@tcs.com

Hi,

  I tried this as well, it doesn't work.

georggeorg

I tried using the following code that worked perfectly for me. Just try it and let us to know the result

 

<apex:page renderAs="pdf" >
<apex:form >
<apex:outputLink value="https://learnsfdc.blogspot.com">Click Here</apex:outputLink>
</apex:form>
</apex:page>

 

**Caution: Use https instead of http while referencing the link

 

Also as a best practice use images from static resources while rendering pdf 

 

Thanks,

George

Visit my blog here

shrey.tyagi88@tcs.comshrey.tyagi88@tcs.com

Thanks a lot for your time Georg. This doesn't wok. I believe the reason it works for you is because you have a link. Links and email addresses are clickable in PDF file( i.e cursor becomes a pointed finger on roll over). But in case of images upon click of an image, its boundaries get highlighted and no redirection happens. Try redirecting upon click of an image rather  than giving it as a link and it wont work.

 

Thanks a lot for your help !!!!