iframe
페이지에 HTML
페이지가 있으며, 내용을로드 할 때 특정 위치로 스크롤해야합니다. 내 예제는 iOS Safari를 제외한 대부분의 브라우저에서 정상적으로 작동합니다. 첫 번째 페이지로드시 iOS Safari에서 작동하는 경향이 있지만 일반적으로 이후에 새로 고침하면 iframe
콘텐츠가 맨 위로 스크롤됩니다.iOS Safari가 iframe에서 앵커로 스크롤하지 않습니다.
리디렉션으로 인해 #anchorname
이 삭제되는 문제에 대해 읽었지 만,이 경우에는 진행되지 않습니다.
실제 iframe
콘텐츠 및 기본 페이지가 다른 도메인에 있습니다. iframe
의 콘텐츠에 영향을 미칠 수는 있지만 제어 할 수는 없습니다. 그것은 또한 다른 목적을 위해 사용되기 때문에, 나는 그것을 방해 할 수있는 관습을 할 수있는 능력이 제한되어있었습니다. 여기
라이브 링크 : 여기 https://s3.amazonaws.com/ios-iframe-test/iframe_test.html
는 부모 내용입니다 :
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<meta content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=0" name="viewport">
<style type="text/css">
#root {
position: relative;
}
#wrapper {
height: 300px;
width: 300px;
overflow-x: hidden;
overflow-y: scroll;
position: relative;
-webkit-overflow-scrolling: touch;
}
iframe {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<h1>Why won't this iframe scroll to where I want?</h1>
<div id="root">
<div id="wrapper">
<iframe src="https://s3.amazonaws.com/ios-iframe-test/iframe_content.html#scrolltome"></iframe>
</div>
</div>
</body>
</html>
그리고 여기 iframe
내용입니다 :
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<h1>Have some ipsum...</h1>
<p>
Lorem... (live example has much more here just to make the scrolling apparent)
</p>
<h1 style="color: red;">
<a name="scrolltome" id="scrolltome">This is where I want to scroll></a>
</h1>
<p>
Lorem...
</p>
</html>
Safari는 iframe에서 스크롤하는 데 많은 문제가 있습니다. JS 솔루션을 사용할 수 있습니까? –