-2

I somehow managed to link a search box to the search box form another website, the problem I have it's that when I put the word I'm looking for it does send me to the page and loads my results but immediately the page reloads to a shorter version of the URL I used to link the search box.

I'm linking the searchbox to a private/corporate sharepoint, and I really need to make it work.

Do you have any idea how could I make it not reload the page everytime?

  • Questions seeking debugging help (**"why isn't this code working?"**) must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it **in the question itself**. Questions without a **clear problem statement** are not useful to other readers. See: [mcve]. – Taplar Jun 29 '18 at 19:23

1 Answers1

0

An easy way would be to add a "Web Part" to Sharepoint with some Javascript that will :

  • get your keyword you put in sharepoint url
  • then in JS you put the keyword in Sharepoint search box, and click on submit

So in 2 steps :

  1. when you type a keyword in your search box outside SharePoint, and click on "Search" button, it redirects to sharepoint page (with search box) with your keyword in the url, like this : ?search=

  2. then you add some Javascript in SharePoint for retrieving your keyword in sharepoint url and fill sharepoint search engine and submit it.

Code for getting the keyword from sharepoint url :

var getUrlParameter = function getUrlParameter(sParam) {
    var sPageURL = decodeURIComponent(window.location.search.substring(1)),
        sURLVariables = sPageURL.split('&'),
        sParameterName,
        i;

    for (i = 0; i < sURLVariables.length; i++) {
        sParameterName = sURLVariables[i].split('=');

        if (sParameterName[0] === sParam) {
            return sParameterName[1] === undefined ? true : sParameterName[1];
        }
    }
};

var keyword = getUrlParameter('keyword ');

And then :

$("#sharepoint_searchbox").val(keyword);
$("#sharepoint_submit_subtton").click();
PierreN
  • 968
  • 4
  • 11
  • Hi Pierre, It's just i'm like a super newbie with coding and all, I'm using wordpress and divi to make this and still trying to figure out all of this the code i'm using is
    – Roger González Jun 29 '18 at 20:16
  • and it sends me to this page 'https://grupometalsa.sharepoint.com/sites/cmo/Shared%20Documents/Forms/AllItems.aspx?view=7&q=' with the word I searched for in the search bar, but it quickly reloads to just this 'https://grupometalsa.sharepoint.com/sites/cmo/Shared%20Documents/Forms/AllItems.aspx' and I don't know how I can fix it. – Roger González Jun 29 '18 at 20:18
  • I think SharePoint is missing some parameter (you don't send him all he wants, or you send him in GET parameter instead of POST) So your request is rejected and SharePoint redirects you to the listing of the document library. (the page AllItems.aspx).. As i haven't anymore a SharePoint online instance, i cannot do an online test... But if you succeed to create a web part (video here https://www.youtube.com/watch?v=l4Occrt_RKY ) i can try to do working code – PierreN Jun 29 '18 at 20:23