Skip to main content
Nintex Community Menu Bar
Question

Redirect URL in JavaScript

  • July 11, 2024
  • 4 replies
  • 222 views
  • Translate All

Forum|alt.badge.img+10

I was searching for the code to redirect to a page within a Salesforce org. I couldn’t find it so here it is. Note “newOrderId.Id” is whatever the variable is for the ID to your new page. Hope this helps someone.

//Redirect to New URL
    var URL = '../../' + newOrderId.Id; 
    var win = window.open(URL, '_blank');```

4 replies

Forum|alt.badge.img+10

Hi Luzie,

I have never used curly brackets within my JS snippets.

Translate

Forum|alt.badge.img+5

Hey Tami, here is some example Javascript code that may help you out.

var $ = skuid.$;
var field = arguments[0];
var value = arguments[1];

switch( field.mode ){
case ‘edit’:
skuid.ui.fieldRenderers[field.metadata.displaytype].edit( field, value );
break;

case 'read':
    var cellElem = field.element;
    var url = '/cp/scenariodetails/'+field.row.id;
    $( '<a href='+url+'>'+value+'</a>' ).appendTo( cellElem );
    break;
    
default:
    var cellElem = field.element;
    var url = '/cp/scenariodetails/'+field.row.id;
    $( '<a href='+url+'>'+value+'</a>' ).appendTo( cellElem );
break;

}

Let us know if it gets you there. Thanks.

Translate

Forum|alt.badge.img+6

Tami, I was on a wrong path here, let me delete my reply to not confuse any more users. Matt will post his response again.

Translate

Forum|alt.badge.img

Use Javascript:

window.location.replace('http://example.com');

It’s better than using window.location.href = ‘http://example.com’;

Using replace() is better because it does not keep the originating page in the session history, meaning the user won’t get stuck in a never-ending back-button fiasco.

If you want to simulate someone clicking on a link, use window.location.href

If you want to simulate an HTTP redirect, use window.location.replace

You can use assign() and replace methods also to javascript redirect to other pages like the following:

location.assign("http://example.com");

The difference between replace() method and assign() method(), is that replace() removes the URL of the current document from the document history, means it is not possible to use the “back” button to navigate back to the original document. So Use the assign() method if you want to load a new document, andwant to give the option to navigate back to the original document.

Translate