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
Satyo IswaraSatyo Iswara 

Javascript redirection won't work in visualforce page

I tried this code for a simple redirection from custom page to record page, but it seems I kept getting cross domain error.
Anybody encounter this?  If yes, is there any known workaround beside using Apex Class?
<apex:page showHeader="false" sidebar="false">
	<script type="text/javascript">
   		window.onload = init;
    
    	function init(){
    		var button = document.getElementById('testButton');
    		button.addEventListener('click',redirectFunct);
    	}
    	function redirectFunct(){
            window.location.href = '/' + '{!$CurrentPage.parameters.id}';
            return false;
        }
	</script>

    <input type="button" value="hello world 2!" onclick="redirectFunct()"/>
	<button id="testButton">
        hello world
    </button>
</apex:page>

 
alsinan nazimalsinan nazim
Hi,

try this:
var link = "/" + "{!$CurrentPage.parameters.id}";
window.location = link;