function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

javascript remoting in VF page that is inside a standard page layout

I have a visualforce page that use javascript remoting that is put inline into a standard page layout.


When I use the page outside of the standard page layout it works fine but when I try to use it inside of the standard layout I receive this error: 


Unsafe JavaScript attempt to access frame with URL from frame with URL Domains, protocols and ports must match.


Anyone experience this before - what does this error mean?


Ohhh, this is a security error. Visualforce pages when put into a standard layout are encapsulated in a frame. Any attempt to access information outside the frame will lead to this error, because visual force code is hosted on an entirly separate domain from regular pages. So this essentially ends up looking like a cross domain attack to the browser, and won't allow it.  Despite my best effots, I have never come to a solid way around this. I really dislike the fact that Salesforce hosts custom code on a separate domain from their regular pages but I guess it makes sense. There may be a fix in the future if you can set headers on visualforce pages to enable CORS requests. But until we can set headers, or visualforce code is hosted on the same domain, inline pages will never be able to interact with the page they are contained in.


What exactly are you trying to do, I have fought with this situation before, and might be able to point you another direction.


I have 3 multiselects built with jquery Chosen.  I want to pass back the selected values to the record.  I've done with with vfPopup button but would like to be able to do it inline.


The options are supplied through a custom object and aren't part of any relationship to the Opportunity.  I would paste the code but it's pretty large - I'll try to break out the important pieces and paste in a follow up post



So my guess is you are having an issue getting the ID of the record your multi selects pertain to? You are trying to read the URL from your visualforce page to figure out what record you are looking at, and that attempt to read the URL is where it's exploding? Otherwise, not sure what you might be doing that is cause that. Can you paste the line that is exploding?


That is exactly it.


in the controller I have:

ctrlId =  ApexPages.currentPage().getParameters().get('Id');

 in the VF as JS I have:


var po_id = '{!ctrlId}';
function remoteCall()
                 //REMOTING ACTION CALL
                 var remote_transaction = new Object();
                 remote_transaction.theId = po_id;
                 poTaxonomy.addselected(JSON.stringify(remote_transaction), function(result,event){



This is what I've done in the past. In your visualforce page, you can access the Id of the record it's embedded in using standard visualforce notation such as {!}. So what I'll do is generally make my visualforce page super light weight and offload most of the code into a component. For example, something like this (with the added bonus it makes it easy to embed this visualforce component in lots of pages, and you only have to maintain/change the component code instead of lots of separate visual force pages).

<apex:page standardcontroller="Opportunity" showHeader="false" sidebar="false" standardStylesheets="false">
    <c:BoxBrowser parentId="{!Opportunity.Id}" />

So then my component actually does the heavy lifting. It receives that ID, and includes it in any visualforce remotin requests. You just pass the Id as a param, instead of trying to read it from the URL or whatever in your Apex code.

Does that make sense?  


Interesting.  Makes sense - I'll have to come back to this later to try and implement it.  Instead of doing it inline I talked them into doing it as a seperate page that is launched from a VF button which isn't ideal but made it easier for the time being.