You need to sign in to do that
Don't have an account?

partial page redirects
I am creating a visualforce page that will live in a section on the contact page. I am trying to get the page to redirect to an external site, but the entire contact page ends up getting redirected. I used to be able to do this easily with S-controls, but I'm running into issues using visualforce. My code is as follows:
<apex:page StandardController="Contact" extensions="pamExt" action="{!getRedir}" > </apex:page>
where as you may have been able to guess getRedir returns a url. Can anyone explain to me why this redirects the entire Contact page and maybe give a way that I can fix this so only this vforce page gets redirected?
Thanks
According to Firebug, the browser is getting error, but Firefox and IE6 ignore that. I remember that IE7 in Windows XP didn't allow it (somehow, my PC, windows 2000 server + IE6, 7 was ok...)... but may be it's not the exact same situation.
Anyway, I test it, and you are right.
Here is the solution.
<apex:page standardController="Contact" extensions="Tmp02Controller"> <script> var url = "{!url}"; if(url != "") window.location.replace(url); </script> </apex:page>
public class Tmp02Controller { private ApexPages.StandardController controller; public Tmp02Controller(ApexPages.StandardController controller) { this.controller = controller; } public string getURL(){ id contactId = controller.getId(); if(contactId == null) return null; Contact c = [select Name from Contact where id = :contactId]; if(c.Name.indexOf('T')==0) return null; return 'https://www.google.com'; } }
For my test, I made it switch the URL based on the Contact Name.
Anyway, if you use window.location.replace() / herf by yourself, it means the iframe, so you can do what you want to do. If you have ajax or dom tool and you have readyDOM function or something like that, that would be better.
Thank you for your interesting post.
ThomasTT
All Answers
That is... unusual situation.
Usually, you CAN NOT redirect the parent contents (because the detail page and VF page are running on different domains and accessing contents in different domain is treated as Cross Site Scripting). Many people wish to do that! I just wonder how you did that... (maybe Fire Fox? but still it doesn't make sense...)
I hope anybody could answer this.
ThomasTT
According to Firebug, the browser is getting error, but Firefox and IE6 ignore that. I remember that IE7 in Windows XP didn't allow it (somehow, my PC, windows 2000 server + IE6, 7 was ok...)... but may be it's not the exact same situation.
Anyway, I test it, and you are right.
Here is the solution.
<apex:page standardController="Contact" extensions="Tmp02Controller"> <script> var url = "{!url}"; if(url != "") window.location.replace(url); </script> </apex:page>
public class Tmp02Controller { private ApexPages.StandardController controller; public Tmp02Controller(ApexPages.StandardController controller) { this.controller = controller; } public string getURL(){ id contactId = controller.getId(); if(contactId == null) return null; Contact c = [select Name from Contact where id = :contactId]; if(c.Name.indexOf('T')==0) return null; return 'https://www.google.com'; } }
For my test, I made it switch the URL based on the Contact Name.
Anyway, if you use window.location.replace() / herf by yourself, it means the iframe, so you can do what you want to do. If you have ajax or dom tool and you have readyDOM function or something like that, that would be better.
Thank you for your interesting post.
ThomasTT
Perfect!
Thanks for the help.
We have a similar requirment, however we need to do a Post to a different site . Is there a way to achieve that.
So basically we will have an iframe which will do a POST to another page, adn the second iFrame should show information from Salesforce.
I appreciate any help you may provide on this
Thanks
If someone has Javascript turned off, this will not work.
jason
If someone would have Javascript turned off, the entire world would collapse (same as "if someone would be using Windows 95...")
Have you ever tried to turn Javascript off and login to salesforce? actually login page doesn't come up if Javascript is turned off...
ThomasTT
Thomas,
Not everyone uses Salesforce directly through logging into Salesforce. The majority of the Salesforce applications I write are Visualforce accessed via Force.com sites. I realize this is not the case for most devs here, and so that is precisely why I chimed in. I am not someone who believes that developers should not rely on Javascript (I use it all the time myself), however, one should be thoughtful about its application. Redirecting a user is generally a critical point of a web application and I would not leave it up to the cooperation of a user's browser if there is a way I can do it on the server side.
I mean no offense here, but your comment regarding turning Javascript off seems a bit short-sighted. If you have a known end-user group, that's one thing. As I said, in my case, I'm generally developing for internationally browseable Force.com sites, and my end-user groups are not controllable. If browser's did not have the option to turn Javascript off, then I'd be the first in line to ignore those pitfalls. Since that's not the case, I will not leave a critical juncture of my application up to the end-user. At the very least, I would have some sort of caveat in place to address situation.
jason