Wednesday, April 9, 2014

Redirect to an external website from SharePoint App

Introduction

I’m assigned to a project where I’m to develop SharePoint hosted app using JSOM.

Problem Background

There I wanted to redirect to external web page. Eg.http://google.com. I used 

  • location.href='http://google.com'; 
  • window.location.replace("http://google.com");
  • document.location.href = url;
which we use normally to redirect to another website. But they didn’t work for me. This is because there was a post back on my page and I still want it.

Solution


I set a Timeout and it worked for me; use the below code to redirect.


   
  setTimeout(function () { document.location.href = url }, 20);

Conclusion


Hope this will help you. :) 

1 comment:

  1. it's not working...
    Sir i want to redirect it from a sharepoint content editor web part

    ReplyDelete