기록을 위해이 시나리오는 하나의 단일 페이지로 구현 될 수 있습니다.
는 잠시 후,
page3.html
로 리디렉션
<html>
<head>
<title>Page 1</title></head>
<body>This is page 1. <input type="button" onclick="toPage2()" value="Go to page 2." /></body></html>
page2.html
<html>
<head>
<title>Page 2</title></head>
<body>This is page 2.</body></html>
에 클릭에 리디렉션 다음 page2.html
을 가지고 page1.html
를 원하는, 당신은 세 페이지가 말
<html>
<head>
<title>Page 3</title></head>
<body>This is page 3.</body></html>
내가해야 할 일 모두 페이지 2의 소스를 가져 와서 일부 자바 스크립트를 삽입 한 다음 소스를 브라우저에로드합니다. 이는 페이지 2가 리디렉션 동작을 인식 할 필요가 없다는 것을 의미합니다.
<html>
<head>
<title>Page 1</title>
<script>
// you can get the source of page 2 via ajax -- still meeting the requirement of javascript/html only.
var source2 = '<html><head><title>Page 2</title></head><body>This is page 2.</body></html>';
function toPage2() {
var page2 = document.open('text/html', 'replace');
var source2injected = inject(source2, 3000, 'page3.html');
window.history.pushState('', '', 'page2.html');
page2.write(source2injected);
page2.close(); }
var left = "<script>setTimeout(function(){window.location='",
middle = "';},",
right = ");</scr" + "ipt>";
function inject (source, time, destination) {
return source.replace('<body>', left + destination + middle + time + right + '<body>'); }
</script></head>
<body>This is page 1. <input type="button" onclick="toPage2()" value="Go to page 2." /></body></html>
나는 이것이 좋은 아이디어 나 당신이 실제로 해결하려고하는 문제에 대한 올바른 해결책이 말하고 있지 않다, 그러나 당신의 질문에 대답 않습니다 따라서, 페이지 1 뭔가처럼 될 것입니다.
왜 내가하고 싶은지 물어볼 수 있습니까? 사용자가 버튼을 클릭 할 때 페이지 3을 직접로드하지 않는 이유는 무엇입니까? – Elior
실제로 달성하고자하는 것을 설명 할 수 있지만 일련의 리디렉션 (예 : AJAX 통화)보다 나은 해결책이 될 수 있습니다. – lxg
클릭 사기 요구 사항처럼 들립니다. 패스. –