2014-09-13 6 views
0

북마크릿은 주소가 자바 스크립트 코드 인 북마크입니다.빙고에 현재 페이지의 URL을 보내기위한 자바 스크립트 북마크

나는 현재 페이지의 URL을 가져 와서 Bing 검색 페이지의 텍스트 상자에 붙여 넣으 려합니다. 내 변수 url에 빙 페이지의 텍스트 상자를 설정하는 방법 다음

javascript:(function(){var%20url=window.location.href;alert(url);})(); 

그러나 한 후 검색합니다

나는 충분히 쉽게 URL을 얻을 수 있나요?

이 작동하지 않습니다

javascript:(function(){var%20url=window.location.href;window.open%20("https://www.bing.com/search?q=&url");})(); 

답변

3

다음 북마크 코드를 사용 : 물론

javascript:{window.location='http://bing.com/search?q='+encodeURIComponent(window.location.href)} 
+0

감사합니다. 나는 다른 사이트 이름 'whoishostingthis'에 다음 코드를 사용하여 동일한 코드를 사용하여 시도했다. javascript : {window.location = 'http : //www.whoishostingthis.com/search? q ='+ encodeURIComponent (window.location.href)}'하지만 실패합니다. 나는 같은 실에서 또 다른 질문을하고 있지만 그것은 밀접하게 관련되어있는 것 같다. – aquagremlin

+0

@acquagremlin 올바른 코드는 다음과 같습니다. javascript : {window.location = 'https : //www.whoishostingthis.com/? q ='+ encodeURIComponent (window.location.href)} – shantanuo

0

당신이 위에서 본 방법을 수행 할 수 있습니다. 그러나, 나는이 상황에서 내 응용 프로그램 내에서 무엇을 보여줄지를 제어하려고했습니다.

그런 다음 Bing API에서 내 애플리케이션에 연결하기로 결정했습니다. 이익은 무료이며 사용자를 귀하의 웹 사이트에서 멀리하지 않을 것입니다.

당신은 여기에 푸른 마켓 플레이스

에서 API 키를 얻을 필요가

은 미래에있을 수 있습니다, 그것을 시도를 제공 할 수있는 코드입니다.

<html> 
<head> 
<title>BING API Integration</title> 
<SCRIPT type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
<script type="text/javascript"> 


$(function() { 
    $('#searchButton').click(function(e){ 
     $("#results").empty(); 
     var query=$('#searchTerm').val(); 
     if (query) { 
      serviceOp = "Web"; 
      search(query, serviceOp); 
     } 
    }); 
}); 

function search(query, serviceOp){ 


    // your account key that youw ill get from https://datamarket.azure.com 
    var acctKey = '<Your Key>'; 

    var rootUri = 'https://api.datamarket.azure.com/Bing/Search'; 

    var requestUri = rootUri + "/" + serviceOp + "?$format=json&Query='" + query + "'"; 


    $.ajax({ 
     type: "GET", 
     url: requestUri, 
     headers: { 
     "Authorization": "Basic " + window.btoa(acctKey + ":" + acctKey) 
     }, 

    }).done(function(o){ 

     if (o.d !== undefined){ 
       var items = o.d.results; 
        for(var idx=0, len= items.length; idx < len; idx++){ 
         var item = items[idx]; 
         switch(item.__metadata.type){ 
          case 'WebResult': 
          showWebResult(item); 
         } 
        } 
       } 
    }); 
} 

// Shows one item of Web result. 

function showWebResult(item) { 

    var p = document.createElement('p'); 
    var a = document.createElement('a'); 
    a.href = item.Url; 
    $(a).append(item.Title); 
    $(p).append(item.Description); 
    $('#results').append(a, p); 
} 
</script> 
</head> 
<body> 
    <label for="searchTerm">Search: </label> 
    <input id="searchTerm" type="text"/> 
    <button id="searchButton">Search</button> 

    <div id="results"> 
    </div> 
</body> 
</html> 
관련 문제