I am trying to redirect to another site (say www.google.com) from a SharePoint site. I tried using window.location.href and window.location.replace but it doesn't work.

It adds the URL to current page URL and displays a page not found error.

The URL is not replacing th epage, instead it just appends at the end of the current page URL. enter image description here


function getItemDetails() {

    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('Reports');

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' + 
        '<Value Type=\'Number\'>1</Value></Geq></Where></Query><RowLimit>10</RowLimit></View>');
    this.collListItem = oList.getItems(camlQuery);


    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceededItem), Function.createDelegate(this, this.onQueryFailedItem));        


function onQuerySucceededItem(sender, args) {

    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
        if(oListItem.get_id() == getParameter('ID')){
            web = oListItem.get_item('Web_x0020_Link');

        window.location.href = web;

function onQueryFailedItem(sender, args) {

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

Can someone help me with this?

  • try window.location.href = 'https://google.com' or window.location.href = '//google.com'. Both worked for me Commented Nov 20, 2015 at 16:52
  • that is what I tried. It is not working
    – Keerthi
    Commented Nov 20, 2015 at 16:54
  • How are you executing this code? Can you show more code? Also add the browser you are testing with. Commented Nov 20, 2015 at 16:56
  • I'm using IE11 and have added the error in my edit
    – Keerthi
    Commented Nov 20, 2015 at 17:01
  • 1
    It navigate to google.com
    – Keerthi
    Commented Nov 20, 2015 at 17:03

1 Answer 1


Solution: Use window.open(url);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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