Jquery location.href 파라미터 - jquery location.href palamiteo

Examples

Get the URL of the current page:

Try it Yourself »

Set the URL of the current page:

location.href = "https://www.w3schools.com";

Try it Yourself »

More examples below.


Definition and Usage

The location.href property sets or returns the entire URL of the current page.


Syntax

Return the href property:

Set the href property:

Property Value

ParameterDescriptionURLAn absolute URL like:
http://www.example.com/default.htm

A relative URL like
default.htm

An anchor URL like
location.href="#top"

A new protocol like:
ftp://someftpserver.com
mailto:[email protected]
file://host/path/example.txt

Return Value

TypeDescriptionA stringThe full URL of the page, including the protocol (like https://).

More Examples

Set the href value to point to an email address (will open and create a new email message):

location.href = "mailto:[email protected]";

Try it Yourself »


Browser Support

location.href is supported in all browsers:

ChromeEdgeFirefoxSafariOperaIEYesYesYesYesYesYes

this actionmethod is not triggered when i debug the code and error is resource cant be found and also how to pass addtional parameters

and also how it can be done with

@Html.ActionLink("HelloPrice", "helloPrice", new { id = item.Id }  , new {@class="myClass"}) 

@class ="myClass" is used to pass additional parameter discountAmount


I think that the problem consist in a discordance between the name of the parameters.

In your jquery code you use:

location.href = "Products/helloPrice?ProductId=" + productId;
(Please note that the parameter is ProductId, with both the initial P and the I in uppercase)

but in your controller the parameter is defined:

public ActionResult helloPrice(int productid)
(Please note that all the name is in lowercase)

I think that the solution is just to call the two parameters exactly the same (including upper o lowercas) in both the controller and the jquery code, that is:
a) ProductId in both
b) or productid in both

I hope this will help you.

Add your solution here

 B   I   U   S  small BIG code var  <   >   &  link [^] encode untab case indent outdent

Preview 0

Existing Members

...or Join us

Download, Vote, Comment, Publish.

Your Email  

This email is in use. Do you need your password?

Optional Password  

When answering a question please:

  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

div#tab_1 {display:none; position:absolute; top:50px; left:50px; width:100px; height:100px; background:red;}

div#tab_2 {display:none; position:absolute; top:150px; left:50px; width:200px; height:200px; background:blue;}

jquery를 사용하여 url 및 url 파라미터를 가져오는 방법

3050 단어 사랑 앞

1. jquery에서 URL을 가져오는 것은 매우 간단합니다. 코드는 다음과 같습니다.
window.location.href;

사실 자바스크립트의 기초인 윈도우 대상만 사용했을 뿐 jquery에 대한 지식은 없었다.
2. jquery가 url 파라미터를 얻는 것은 비교적 복잡하고 정규 표현식을 사용해야 하기 때문에 자바스크립트 정규식을 배우는 것이 얼마나 중요한 일인가
우선 단순히 자바스크립트를 통해 url의 어떤 인자를 어떻게 가져오는지 살펴보자.
   //  url    
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //                  
        var r = window.location.search.substr(1).match(reg);  //      
        if (r != null) return unescape(r[2]); return null; //     
    }

이 함수를 통해 URL의 매개 변수 이름을 전달하면 매개 변수의 값을 얻을 수 있습니다. 예를 들어 URL은
http://localhost:33064/WebForm2.aspx?reurl=WebForm1.aspx
다음과 같이 reurl의 값을 가져옵니다.
var xx = getUrlParam('reurl');

자바스크립트가 url 파라미터를 가져오는 방법을 알았습니다. 이 방법으로 jquery를 확장해서 jquery를 통해 url 파라미터를 가져올 수 있습니다. 다음 코드는 jquery로 getUrlParam() 방법을 확장할 수 있습니다.

            (function ($) {
                $.getUrlParam = function (name) {
                    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                    var r = window.location.search.substr(1).match(reg);
                    if (r != null) return unescape(r[2]); return null;
                }
            })(jQuery);

jquery를 위해 이 방법을 확장하면 다음과 같은 방법으로 매개 변수의 값을 얻을 수 있습니다.
   var xx = $.getUrlParam('reurl');

전체 코드:

        $(function () {

            //   :
            (function ($) {
                $.getUrlParam = function (name) {
                    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                    var r = window.location.search.substr(1).match(reg);
                    if (r != null) return unescape(r[2]); return null;
                }
            })(jQuery);

            //   :
            var xx = $.getUrlParam('reurl');

            //   :
            // var xx = getUrlParam('reurl');


            alert(xx);

        });

        //   :
        //  url    
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //                  
            var r = window.location.search.substr(1).match(reg);  //      
            if (r != null) return encodeURI(r[2]); return null; //     
        }


 

JavaScript unescape() 함수
정의 및 사용
unescape () 함수는 escape () 인코딩을 통해 문자열을 디코딩할 수 있습니다.
매개 변수
묘사
string
필요합니다.디코딩하거나 반전할 문자열입니다.
설명
이 함수의 작업 원리는 다음과 같다. x x x와% uxxx 형식의 문자 서열 (x는 16진수를 나타내는 숫자) 을 찾아서 유니코드 문자\u00xx와\uxxxx로 이런 문자 서열을 대체하여 디코딩한다.
프롬프트 및 주석
참고: ECMAScript v3 unescape() , , decodeURI() decodeURIComponent() 。요약:javascript는 매개 변수에 대한 인코딩 방법이 일치해야 한다.
escape() unescape()
encodeURI() decodeURI()
encodeURIComponent() decodeURIComponent()
주소

angularjs와 jquery의 CRUD 차이

js 보고서 TypeError $(...)is null 오류, jquery 실효의 원인 및 해결 방법

좋은 웹페이지 즐겨찾기

개발자 우수 사이트 수집

개발자가 알아야 할 필수 사이트 100선 추천 우리는 당신을 위해 100개의 자주 사용하는 개발자 학습 사이트를 정리했습니다