itsource

JavaScript: 위치.새 창/탭에서 여는 href를 선택하십시오.

mycopycode 2022. 11. 14. 21:41
반응형

JavaScript: 위치.새 창/탭에서 여는 href를 선택하십시오.

서드파티 개발자의 JavaScript 파일을 가지고 있습니다.에는 현재 페이지를 대상으로 대체하는 링크가 있습니다.이 페이지를 새 탭으로 열고 싶습니다.

지금까지 제가 알아낸 건 다음과 같습니다.

if (command == 'lightbox') {
 location.href="https://support.wwf.org.uk/earth_hour/index.php?type=individual";
}

누가 나 좀 도와줄래?

window.open(
  'https://support.wwf.org.uk/earth_hour/index.php?type=individual',
  '_blank' // <- This is what makes it open in a new window.
);

사용하고 싶은 경우location.href팝업 문제를 피하기 위해 빈칸을 사용할 수 있습니다.<a>참조 후 javascript를 사용하여 클릭합니다.

HTML에서와 같은 것

<a id="anchorID" href="mynewurl" target="_blank"></a>

그런 다음 다음과 같이 javascript를 클릭합니다.

document.getElementById("anchorID").click();

window.open 대신 순수 js.

let a= document.createElement('a');
a.target= '_blank';
a.href= 'https://support.wwf.org.uk/';
a.click();

다음으로 작업 예를 나타냅니다(스택오버플로우 스니펫은 오픈할 수 없습니다).

를 사용하여 새 창에서 열 수 있습니다.window.open('https://support.wwf.org.uk/earth_hour/index.php?type=individual');. 새 탭에서 현재 페이지를 열고 현재 페이지와 새 페이지를 모두 얻을 수 있도록 스크립트를 2개의 탭으로 열고 실행할 스크립트를 모두 낮춥니다.

로케이션의 사용방법.href 는, 같은 Web 페이지의 현재의 URL 를 새로운 URL(https://support.wwf.org.uk/earth_hour/index.php?type=individual)로 치환합니다.

새 탭을 열려면 다음과 같이 사용할 수 있습니다. if (명령 == 'lightbox') { window.open https://support.wwf.org.uk/earth_hour/index.php?type=individual", '_blank'; }

예를 들어 다음과 같습니다.

    $(document).on('click','span.external-link',function(){
        var t               = $(this), 
            URL             = t.attr('data-href');        
        $('<a href="'+ URL +'" target="_blank">External Link</a>')[0].click();

    });

작업

또한 다음과 같은 매개 변수를 사용하여 액션 메서드를 호출하는 새 탭을 열 수도 있습니다.

   var reportDate = $("#inputDateId").val();
   var url = '@Url.Action("PrintIndex", "Callers", new {dateRequested = "findme"})';
   window.open(window.location.href = url.replace('findme', reportDate), '_blank');

언급URL : https://stackoverflow.com/questions/5141910/javascript-location-href-to-open-in-new-window-tab

반응형