Menu
I have a problem with anchor.
Can somebody help me with this …
Code page1.php
`<a href=’https://domain.com/page1.php#$row[3]’>goto anchor on page2</a>
Code page2.php
`<a name=’$row[3}’>anchor</a>
This doesn’t work.
What am I doing wrong?
Please help me …
Best regards
<a id="$row[3]">anchor</a>
[code=php]
<a id="<?php echo $row[3]; ?>">anchor</a>
[/code]
https://domain.com/page1.php#1234
<a id="<?php echo $row[3]; ?>">anchor</a>
>@ginerjm#1636794 Code page1.php
> <a href='[https://domain.com/page1.php#1234'>goto](https://domain.com/page1.php#1234%27%3Egoto) anchor on page2</a>
>
> Code page2.php
> <a name='1234'>anchor</a>
<a href='https://domain.com/page**2**.php#1234'>goto anchor on page2</a>
<a href="page2.php?taal=en#Basil"><img style="cursor: url('magnify.cur'),default;" src="upload/Basil_(3).jpg" width="auto" height="185">
<a id="Basil">Basil</a>
#1234
#1234
id=
name=
>@ginerjm
> PS - this is not what you started this topic with. Not nice.
What do mean? The code I started with is the code of the PHP page I wrote. The last code I gave you is source view in the browser (result) and simplified the code a little bit. Instead of a text I used a picture.
>@ginerjm
> Can you write an href that includes not only the target id but also a query element?
<a href="page2.php?taal=en#Basil"><img style="cursor: url('magnify.cur'),default;" src="upload/Basil_(3).jpg" width="auto" height="185"></a>
<a id="Basil">Basil</a>
#
``<i>
</i> <script type='text/javascript'>
/* <![CDATA[ */
function frameSize(id){
var theheight;
document.getElementById(id).height = 0;
if(document.getElementById) {
theheight = document.getElementById(id).contentWindow.document.body.scrollHeight;
}
document.getElementById(id).height = theheight;
}
/* ]]> */
</script>
<iframe src="page1.php?taal=<?php echo($taal)?>" name="test" id="test" width="100%" height="100%"
frameborder="0" marginwidth="0" scrolling="no" style="visibility:hidden;" allowTransparency="true" onload="frameSize('test'); this.style.visibility = 'visible';"><i>
</i>
``
iframe
src
iframe
iframe
>The only thing the main page that contains that iframe could target via the main page URL is the ID of the iframe element itself -- not anything in its content.
location.hash
```<i>
</i><!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
<style>
</style>
</head>
<body>
<iframe id="iframe1" src="thread730-the-iframe.html"></iframe>
<script>
// Provide iFrame:
const iframe = document.getElementById('iframe1');
// Add hash of current page to src attribute:
iframe.src += location.hash;
</script>
</body>
</html><i>
</i>
`</CODE>
And for testing I used this HTML in the iframe:
<CODE>
`<i>
</i><!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
<style>
div {
height: 150vh;
}
#container1 {
background-color: bisque;
}
#container2 {
background-color: lightblue;
}
#container3 {
background-color: lightcoral;
}
</style>
</head>
<body>
<div id="container1">Box 1</div>
<div id="container2">Box 2</div>
<div id="container3">Box 3</div>
</body>
</html><i>
</i>
`</CODE>
And the page containing the links:
<CODE>
`<i>
</i><!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
<style>
</style>
</head>
<body>
<a href="thread730-anchor-inside-iframe-page2.html#container1">Goto Page 2 Box 1</a>
<a href="thread730-anchor-inside-iframe-page2.html#container2">Goto Page 2 Box 2</a>
<a href="thread730-anchor-inside-iframe-page2.html#container3">Goto Page 2 Box 3</a>
</body>
</html><i>
</i>
``
>it's with a scrollbar on the right
scrolling="no"
`>The biggest problem is the lytebox (view pop-up photo).
``<i>
</i> <script>
function frameSize(id) {
// set height of frame:
const theFrame = document.getElementById(id),
frameDoc = theFrame.contentWindow.document,
frameHeight = frameDoc.body.scrollHeight;
// set height of frame:
theFrame.height = frameHeight;
const
// get URL of frame:
url = theFrame.contentWindow.location.search,
// get URL parameters:
urlParams = new URLSearchParams(url),
// get current item form URL params:
item = urlParams.get('item');
if (item) {
const
// get element being addressed:
ele = frameDoc.getElementById(item),
// get top position of this element relative to viewport:
boxEle = ele.getBoundingClientRect(),
topEle = boxEle.top,
// get position of frame relative to document:
boxFrame = theFrame.getBoundingClientRect(),
topFrame = boxFrame.top + document.documentElement.scrollTop,
// get scroll position:
scrollPos = topFrame + topEle;
// scroll document in order to make element visible:
document.documentElement.scrollTop = scrollPos;
}
// }
}
</script><i>
</i>
`</CODE>
Replace your old script:
<CODE>
`<i>
</i> <script type='text/javascript'>
/* <![CDATA[ */
function frameSize(id){
var theheight;
document.getElementById(id).height = 0;
if(document.getElementById) {
theheight = document.getElementById(id).contentWindow.document.body.scrollHeight;
}
document.getElementById(id).height = theheight;
}
/* ]]> */
</script><i>
</i>
`</CODE>
by the new one. I used a query string in order to avoid confusion by hash vs. url params. Therefore you will have to change your links to this pattern:<br/>
<C>
<a href="index_nieuw_bestellen.php?taal=de&item=container1"><img ...></a>
`
where container1 is the ID of the element. The script will make this element visible.
My test configuration here:
https://webentwicklung.ulrichbangert.de/thread730-master-2.html
If this doesn't work, put in online and come back.
index_nieuw_bestellen.php?taal=de
</C>. Say the ID of the item is "Jolene" then the link should read: <C>
index_nieuw_bestellen.php?taal=de&item=Jolene
</C>.</LI>
<LI>2. In the second page add the ID to the item like this:
<CODE>
`<i>
</i><div align="center" id="Jolene" style="width:290px;float:left;margin-bottom:10px;list-style-type: none;">
<div stye="position:absolute;">
<a href="index_nieuw_bestellen.php?taal=de" style="text-decoration: none;">
<img style="cursor: url('magnify.cur'),default;" src="upload/Jolene8.jpg" width="auto" height="185"></a><div style="font-size:12px;position:relative;margin-top:-35px;padding:5px 0px 5px 0px;width: 140px;-webkit-border-radius: 10px;-moz-border-radius: 10px;-opera-border-radius:10px;border-radius: 10px;box-shadow:0 0 10px #666;-moz-box-shadow: 0 0 10px #666;-webkit-box-shadow: 0 0 10px #666;background-color:#b67637;color: #faeaa7;">Jolene&nbsp;&nbsp;45 cm</div></div><div style="margin-top:25px;"></div><form name="form_afbeelding"><input type="hidden" name="taal" id="taal" value="de"></form><i>
</i>
`</CODE></LI></LIST>
BTW: Framesets and attributes like <C>
align="center"
```<i>
</i> <script>
function frameSize(id) {
// set height of frame:
const theFrame = document.getElementById(id),
frameDoc = theFrame.contentWindow.document,
frameHeight = frameDoc.body.scrollHeight;
// set height of frame:
theFrame.height = frameHeight;
const
// get URL of frame:
url = theFrame.contentWindow.location.search,
// get URL parameters:
urlParams = new URLSearchParams(url),
// get current item form URL params:
item = urlParams.get('item');
if (item) {
const
// get element being addressed:
ele = frameDoc.getElementById(item),
// get top position of this element relative to viewport:
boxEle = ele.getBoundingClientRect(),
topEle = boxEle.top,
// get position of frame relative to document:
boxFrame = theFrame.getBoundingClientRect(),
topFrame = boxFrame.top + window.scrollY,
// get scroll position:
scrollPos = topFrame + topEle;
// scroll document in order to make element visible:
if (typeof document.documentElement.scrollTop != undefined) {
document.documentElement.scrollTop = scrollPos;
} else {
document.body.scrollTop = scrollPos;
}
}
}
</script><i>
</i>
``
>URLSearchParams is not supported in all versions of safari or older browsers.
>galleries_nieuw.php?taal=de:275 Uncaught TypeError: Cannot read property 'getBoundingClientRect' of null
``<i>
</i> <script>
// script here
</script>
</body>
</html><i>
</i>
``
``<i>
</i> <script>
function logIt(txt) {
const out = document.getElementById('output');
out.innerHTML += txt;
}
function frameSize(id) {
try {
// set height of frame:
const theFrame = document.getElementById(id),
frameDoc = theFrame.contentWindow.document,
frameHeight = frameDoc.body.scrollHeight;
// set height of frame:
theFrame.height = frameHeight;
const
// get URL of frame:
url = theFrame.contentWindow.location.search,
// get URL parameters:
urlParams = new URLSearchParams(url),
// get current item form URL params:
item = urlParams.get('item');
logIt('item=' + item);
if (item) {
const
// get element being addressed:
ele = frameDoc.getElementById(item),
// get top position of this element relative to viewport:
boxEle = ele.getBoundingClientRect(),
topEle = boxEle.top,
// get position of frame relative to document:
boxFrame = theFrame.getBoundingClientRect(),
topFrame = boxFrame.top + window.scrollY,
// get scroll position:
scrollPos = topFrame + topEle;
logIt(' topEle=' + topEle + ' topFrame=' + topFrame + ' scrollPos=' + scrollPos);
// scroll document in order to make element visible:
if (typeof document.documentElement != undefined) {
document.documentElement.scrollTop = scrollPos;
} else {
document.body.scrollTop = scrollPos;
}
}
}
catch (e) {
logIt(e);
}
}
</script><i>
</i>
`</CODE>
The function logIt writes some debug info to a container div#output. Please add this container to the masterpage where the script is located in:
<CODE>
`<i>
</i> <div id="output"></div><i>
</i>
``
``<i>
</i> <script>
function logIt(txt) {
const out = document.getElementById('output');
out.innerHTML += txt;
}
function frameSize(id) {
try {
// set height of frame:
const theFrame = document.getElementById(id),
frameDoc = theFrame.contentWindow.document,
frameHeight = frameDoc.body.scrollHeight;
// set height of frame:
theFrame.height = frameHeight;
const
// get URL of frame:
url = theFrame.contentWindow.location.search,
// get URL parameters:
urlParams = new URLSearchParams(url),
// get current item form URL params:
item = urlParams.get('item');
logIt('item=' + item);
if (item) {
const
// get element being addressed:
ele = frameDoc.getElementById(item),
// get top position of this element relative to viewport:
boxEle = ele.getBoundingClientRect(),
topEle = boxEle.top,
// get position of frame relative to document:
boxFrame = theFrame.getBoundingClientRect(),
topFrame = boxFrame.top + window.scrollY,
// get scroll position:
scrollPos = topFrame + topEle;
logIt(' topEle=' + topEle + ' topFrame=' + topFrame + ' scrollPos=' + scrollPos);
// scroll document in order to make element visible:
if (typeof document.documentElement != undefined) {
document.documentElement.scrollTop = scrollPos;
logIt(' scrollPos_on_document.documentElement=' + document.documentElement.scrollTop);
} else {
document.body.scrollTop = scrollPos;
logIt(' scrollPos_on_document.body=' + document.body.scrollTop);
}
}
}
catch (e) {
logIt(e);
}
}
</script><i>
</i>
``
``<i>
</i> <script>
function logIt(txt) {
const out = document.getElementById('output');
out.innerHTML += txt;
}
function frameSize(id) {
try {
// set height of frame:
const theFrame = document.getElementById(id),
frameDoc = theFrame.contentWindow.document,
frameHeight = frameDoc.body.scrollHeight;
// set height of frame:
theFrame.height = frameHeight;
const
// get URL of frame:
url = theFrame.contentWindow.location.search,
// get URL parameters:
urlParams = new URLSearchParams(url),
// get current item form URL params:
item = urlParams.get('item');
logIt(' item=' + item);
if (item) {
const
// get element being addressed:
ele = frameDoc.getElementById(item),
// get top position of this element relative to viewport:
boxEle = ele.getBoundingClientRect(),
topEle = boxEle.top,
// get position of frame relative to document:
boxFrame = theFrame.getBoundingClientRect(),
topFrame = boxFrame.top + window.scrollY,
// get scroll position:
scrollPos = topFrame + topEle;
logIt(' topEle=' + topEle + ' topFrame=' + topFrame + ' scrollPos=' + scrollPos);
// scroll document in order to make element visible:
if (typeof document.scrollingElement != undefined) {
document.scrollingElement.scrollTop = scrollPos;
logIt(' scrollPos_on_document.scrollingElement=' + document.scrollingElement.scrollTop);
} else {
// document.body.scrollTop = scrollPos;
logIt(' document.scrollingElement_is_undefined');
}
}
}
catch (e) {
logIt(e);
}
}
</script><i>
</i>
``
logIt(' scrollPos_on_document.scrollingElement=' + document.scrollingElement.scrollTop);
`>scrollPos_on_document.**scrollingElement**=xxxx
``<i>
</i> <script>
function logIt(txt) {
const out = document.getElementById('output');
out.innerHTML += txt;
}
function frameSize(id) {
try {
// set height of frame:
const theFrame = document.getElementById(id),
frameDoc = theFrame.contentWindow.document,
frameHeight = frameDoc.body.scrollHeight;
// set height of frame:
theFrame.height = frameHeight;
const
// get URL of frame:
url = theFrame.contentWindow.location.search,
// get URL parameters:
urlParams = new URLSearchParams(url),
// get current item form URL params:
item = urlParams.get('item');
logIt(' item=' + item);
if (item) {
const
// get element being addressed:
ele = frameDoc.getElementById(item),
// get top position of this element relative to viewport:
boxEle = ele.getBoundingClientRect(),
topEle = boxEle.top,
// get position of frame relative to document:
boxFrame = theFrame.getBoundingClientRect(),
topFrame = boxFrame.top + window.scrollY,
// get scroll position:
scrollPos = topFrame + topEle;
logIt(' topEle=' + topEle + ' topFrame=' + topFrame + ' scrollPos=' + scrollPos);
// scroll document in order to make element visible:
if (typeof document.scrollingElement != undefined) {
document.scrollingElement.scrollTop = scrollPos;
logIt(' scrollPos_on_document.scrollingElement=' + document.scrollingElement.scrollTop);
} else {
// document.body.scrollTop = scrollPos;
logIt(' document.scrollingElement_is_undefined');
}
}
}
catch (e) {
logIt(e);
}
}
</script><i>
</i>
`</CODE>
The relevant section is this:
<CODE>
`<i>
</i> if (typeof document.scrollingElement != undefined) {
document.scrollingElement.scrollTop = scrollPos;
logIt(' scrollPos_on_document.scrollingElement=' + document.scrollingElement.scrollTop);
} else {
// document.body.scrollTop = scrollPos;
logIt(' document.scrollingElement_is_undefined');
}<i>
</i>
`</CODE>
take notice of <C>
scrollingElement
`.
>I can live with that!
>cleared history, data, cache, ... on the iPad but still get the same results
0.1.9 — BETA 5.1