일부 웹 사이트는 “크리에이티브”(자바 스크립트?) 하이퍼 링크를 사용하여 새 탭에서 열려면 Ctrl + 클릭 또는 가운데 클릭 링크와 같은 브라우저 기능을 손상시킵니다.
일반적인 예는 taleo HR 웹 사이트
http://www.rogers.com/web/Careers.portal?_nfpb=true&_pageLabel=C_CP&_page=9
내가 무엇을 시도하든 정상적으로 링크를 클릭해야만 링크를 따라갈 수 있습니다. 새 창에서 열 수 없습니다. 이 주위에 어떤 방법이 있습니까?
답변
귀하의 질문은 Taleo에만 국한되므로 내 대답은 너무 될 것입니다 🙂
원하는 것을하는 UserScript를 코딩했습니다. 모든 JavaScript 링크를 일반 링크로 대체하므로 원하는 경우 클릭하거나 새 탭에서 열 수 있습니다.
// ==UserScript==
// @name Taleo Fix
// @namespace https://github.com/raphaelh/taleo_fix
// @description Taleo Fix Links
// @include http://*.taleo.net/*
// @include https://*.taleo.net/*
// @version 1
// @grant none
// ==/UserScript==
function replaceLinks() {
var rows = document.getElementsByClassName("titlelink");
var url = window.location.href.substring(0, window.location.href.lastIndexOf("/") + 1) + "jobdetail.ftl";
for (var i = 0; i < rows.length; i++) {
rows[i].childNodes[0].href = url + "?job=" + rows[i].parentNode.parentNode.parentNode.parentNode.parentNode.id;
}
}
if (typeof unsafeWindow.ftlPager_processResponse === 'function') {
var _ftlPager_processResponse = unsafeWindow.ftlPager_processResponse;
unsafeWindow.ftlPager_processResponse = function(f, b) {
_ftlPager_processResponse(f, b);
replaceLinks();
};
}
if (typeof unsafeWindow.requisition_restoreDatesValues === 'function') {
var _requisition_restoreDatesValues = unsafeWindow.requisition_restoreDatesValues;
unsafeWindow.requisition_restoreDatesValues = function(d, b) {
_requisition_restoreDatesValues(d, b);
replaceLinks();
};
}
https://github.com/raphaelh/taleo_fix/blob/master/Taleo_Fix.user.js에서 찾을 수 있습니다.
답변
예. Greasemonkey (Firefox) 또는 Tampermonkey (Chrome)에 대한 고유 한 스크립트를 작성할 수 있습니다.
언급 한 예 에서이 Tampermonkey UserScript는 검색 결과의 모든 JavaScript 링크를 새 탭 / 창에서 열리도록 설정합니다 (브라우저 구성에 따라 다르며 탭입니다).
// ==UserScript==
// @name open links in tabs
// @match http://rogers.taleo.net/careersection/technology/jobsearch.ftl*
// ==/UserScript==
document.getElementById('ftlform').target="_blank"
더 일반적인 버전을 작성할 수 있지만 다른 유용성을 손상시키지 않고 모든 JavaScript 링크에 대해이 기능을 활성화하는 것은 어렵습니다.
미들 패스는에 대한 이벤트 핸들러를 설정하는 것이 될 수 있으며 Ctrl, 키를 누르고있는 한 모든 양식의 대상을 “_blank”로 임시 설정합니다.
답변
요소에 onclick="document.location='some_url'"속성이있는 <a href=some_url>요소 를 감싸고를 제거하는 다른 사용자 스크립트 가 onclick있습니다.
특정 사이트 용으로 작성했지만 다른 사람에게 유용 할 정도로 일반적입니다. 아래 @match URL 을 변경하는 것을 잊지 마십시오 .
링크가 AJAX 호출에 의해로드 될 때 작동하므로 MutationObserver가 작동합니다.
// ==UserScript==
// @name JavaScript link fixer
// @version 0.1
// @description Change JavaScript links to open in new tab/window
// @author EM0
// @match http://WHATEVER-WEBSITE-YOU-WANT/*
// @grant none
// ==/UserScript==
var modifyLink = function(linkNode) {
// Re-create the regex every time, otherwise its lastIndex needs to be reset
var linkRegex = /document\.location\s*=\s*\'([^']+)\'/g;
var onclickText = linkNode.getAttribute('onclick');
if (!onclickText)
return;
var match = linkRegex.exec(onclickText);
if (!match) {
console.log('Failed to find URL in onclick text ' + onclickText);
return;
}
var targetUrl = match[1];
console.log('Modifying link with target URL ' + targetUrl);
// Clear onclick, so it doesn't match the selector, before modifying the DOM
linkNode.removeAttribute('onclick');
// Wrap the original element in a new <a href='target_url' /> element
var newLink = document.createElement('a');
newLink.href = targetUrl;
var parent = linkNode.parentNode;
newLink.appendChild(linkNode);
parent.appendChild(newLink);
};
var modifyLinks = function() {
var onclickNodes = document.querySelectorAll('*[onclick]');
[].forEach.call(onclickNodes, modifyLink);
};
var observeDOM = (function(){
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
return function(obj, callback) {
if (MutationObserver) {
var obs = new MutationObserver(function(mutations, observer) {
if (mutations[0].addedNodes.length || mutations[0].removedNodes.length)
callback();
});
obs.observe(obj, { childList:true, subtree:true });
}
};
})();
(function() {
'use strict';
observeDOM(document.body, modifyLinks);
})();