0

I want to add a custom link in output text and it will redirects to external url.

So I added below code.,

<apex:outputText><td><div><a href="#" target="_blank" onclick="window.open('{!b.URL__c}')" >{!b.Number__c)}</a></div></td></apex:outputText>

For example the custom object field url__c is www.google.com.

So I am expecting the output as www.google.com once i select the link. But it is coming that www.na1.salesforce.com/www.google.com.

How to fix this?

Please help me.

Thanks, Krishna.

1
  • Any reason why you don't do <a href="{!b.URL__c}" target="_blank"> or why you not use apex:outputLink ? – Bartheleway Jan 20 at 17:01
-1

Please Find The Exact Solution Of You Question. 100% working..

You just need to use window.location.replace('url') . No need to use target="_blank"

       <a href="javascript:window.location.replace('{!b.URL__c}')">Same Page No Need Of _Blank</a>
1
  • Salesforce Stack Exchange is not a conversational forum, like the Developer Forums. We don't have "best answer" here, and you should refrain from asking for votes and answer acceptance. Please also do not ask for responses from the asker - your answer should stand alone for all readers. – David Reed Jan 23 at 14:58
-1

Please find the solution. redirect external url in visualforce page

<apex:page >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:outputLink onclick="window.open('https://www.google.com/',
               'Popup','height=500,width=800,left=100,top=100,scrollbars=yes,toolbar=no,status=no');">
                    Go To Next Page
                </apex:outputLink>
                
                <a href="javascript:window.open('https://www.google.com/')">Change </a>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

You can use like this for redirect window.open('URL', 'Popup','height=500,width=800,left=100,top=100,scrollbars=yes,toolbar=no,status=no');

<apex:page >
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
    <apex:CommandLink Value="GO TO Next Page" onclick="window.open('https://www.google.com/')"/>
    <apex:CommandLink Value="GO TO Same Page With PopUp " onclick="SamePage('https://www.google.com/')"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    <script language="javascript" type="text/javascript">
    
    function SamePage(url) {
        newwindow=window.open(url,'Malika','height=500,width=750');
        if (window.focus) {newwindow.focus()}
        return false;
    }
    </script>
</apex:page>
1
  • Please use the tools in the editor to format your code correctly. Please consider combining your two answers and providing clear explanation as to what the problem is in the original code. – David Reed Jan 23 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.