Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
一个用于获取输入页面的加载javascript;然后将两个css id设置为display:none”和“display:inline”,切换两个可用的_Javascript_Css_Html - Fatal编程技术网

一个用于获取输入页面的加载javascript;然后将两个css id设置为display:none”和“display:inline”,切换两个可用的

一个用于获取输入页面的加载javascript;然后将两个css id设置为display:none”和“display:inline”,切换两个可用的,javascript,css,html,Javascript,Css,Html,请注意,我不太了解javascript向导。如果能在页面加载时提供帮助,我将不胜感激,返回一个值或字符串作为最终本地路径的来源,以便指示脚本的其余部分进行硬编码比较,或者将结果进行硬编码比较;并且,根据结果,切换两个css id,这两个css id分别有一个id包含一个display:none和另一个display:inline,以控制页面底部链接的方式,并通过两个不同菜单页面中的哪一个是其实际原始父菜单页面来确定设计的导航选项。 提到的css ID最初将在新内容子页面“样式”部分中本地设置,如

请注意,我不太了解javascript向导。如果能在页面加载时提供帮助,我将不胜感激,返回一个值或字符串作为最终本地路径的来源,以便指示脚本的其余部分进行硬编码比较,或者将结果进行硬编码比较;并且,根据结果,切换两个css id,这两个css id分别有一个id包含一个display:none和另一个display:inline,以控制页面底部链接的方式,并通过两个不同菜单页面中的哪一个是其实际原始父菜单页面来确定设计的导航选项。 提到的css ID最初将在新内容子页面“样式”部分中本地设置,如下所示:

#MyDisplayOnOff-0 {display:inline;}
and
#MyDisplayOnOff-1 {display:none;}
href发送页面将是以下两个菜单之一: ./MenuONE.html或./MenuONE.htmlTop或./MenuONE.htmlBottom 或 ./SECONDMenu.html或./SECONDMenu.htmlTop或./SECONDMenu.htmlBottom

[关于./MenuONE.html的实际示例]:

到目前为止,当从两个不同的菜单中选择相同的内容时,我创建了两个名称略有不同的html页面,其中包含相同的内容,但底部有不同的导航链接。我宁愿使用一个html页面,用两个备选链接硬编码,然后使用初始javascrip的结果t返回'sending page',用一个'display:none'和另一个'display:inline'适当地填充两个css ID,以便只显示其中一个 下面是两个现实世界中的例子,它们分别位于不同的[名称稍有不同]html页面上,每个页面都有不同的底部链接结构,设计时需要从不同的菜单中调用每个页面

我觉得javascript中可能需要的是:

我被要求添加所使用的html。例如,html内容的主体在底部有链接

<div id="BottomRightpNAV">
    <a href="./Menu%20-%20Rivers%20of%20Mind%20and%20Heart.html">Rivers of Mind and Heart</a>
</div>  
链接示例:在上面讨论的css样式上方的一条注释,在任意示例中,将选择第二个不同的链接。一次只显示一个。每个链接包含一个css id[有效地允许打开或关闭一个或另一个],将显示在一起,硬编码如下

<div id="BottomRightpNAV">
    <a id="MyDisplayOnOff-0" href="./Menu%20-%20Rivers%20of%20Mind%20and%20Heart.html">Rivers of Mind and Heart</a>

    <a id="MyDisplayOnOff-1" href="./Menu%20-%20Of%20Lila%20and%20the%20Void.html">Of Lila and the Void</a>
</div>

因此,总的来说,取决于用户输入的两个菜单中的哪一个页面,它将显示两个可用链接中的一个,并隐藏另一个链接。

如果我理解正确,您可以尝试以下方法:

使每个链接包含一个查询参数:

<a href="something.com?redictedFrom=page1">my link's text</a>
<a href="something.com?redictedFrom=page2">my link's text</a>

您也可以使用window.location.search.split'&'获取单个键值对,还可以使用string.split'='将它们分隔开。但这超出了问题的直接范围。

由于@Andu Andrici提供了出色的建议和代码示例,该解决方案得以启动。它是通过从pa“推送”信息实现的租用菜单pageA或pageB,以确定哪个页面打开了公共子内容页。尝试从历史记录中获取原始页面及其安全限制,或者在Cookie之外,由于无法写入css或脚本文件,因此这是一个理想而优雅的解决方案。在子内容页上,这两个菜单都通用页面上,它是用javascript加上“if”语句的:因此,未更改的内容具有独特的、与众不同的链接,然后任意放在底部

zMenuA.html简化如下:

<!doctype html>
<html>
<head>
<title>zMenuA.html [Acknowledgement @Andu Andrici]</title>
</head>
<body>

<a href="./zSameTarget.html?redictedFrom=zMenuA">zMenuA.html invoking zSameTarget.html</a>

</body>
</html>
<!doctype html>
<html>
<head>
<title>zMenuB.html [Acknowledgement @Andu Andrici]</title>
</head>
<body>

<a href="./zSameTarget.html?redictedFrom=zMenuB">zMenuB.html invoking zSameTarget.html</a>

</body>
</html>
<!doctype html>
<html>
<head>
<title>zSameTarget.html [Acknowledgement @Andu Andrici]</title>
<style></style>

<script type="text/javascript">
    var MyAppendedUrlMarker = window.location.search

    if (MyAppendedUrlMarker === '?redictedFrom=zMenuA') {
    onload = function () {
    document.head.insertAdjacentHTML('beforeend', "<link href='addOtherCSSstyling.css' type='text/css' rel='stylesheet'/>");

        var MyElement = 
document.getElementById("MyDisplayOnOff0").style.display = "inline";
        var MyElement = 
document.getElementById("MyDisplayOnOff1").style.display = "none";
        }
    }

    if (MyAppendedUrlMarker === '?redictedFrom=zMenuB') { 
    onload = function () {
        var MyElement = 
document.getElementById("MyDisplayOnOff0").style.display = "none";
        var MyElement = 
document.getElementById("MyDisplayOnOff1").style.display = "inline";
        }        
    }
</script>

</head>

<body>

<p style="white-space:pre-wrap;">
This is the child page 'zSameTarget.html' with this content showing 
the same; BUT, at the bottom, with different content [a navigation link] 
being visible and active, solely dictated by which parent page invoked 
this page. To whit, whether in opening this page, an [a href ....] was 
clicked on 'zMenuA.html', or if it came from a click originating from 
'zMenuB.html' instead. NOTE: running this page alone will show two links. 
It is meant to show only one link. Therefore, first open 'zMenuA.html' 
or 'zMenuB.html' and then link to this page from either one of them. As
indicated, depending on the page chosen, one will find it has produced a 
different content [link in this case] visible at the bottom. As well, I 
have added a linked 'myFile.css' to modify the styling elsewhere when
'zMenuA.html' is identified as the parent in the 'if' statements.</p><br/>

    <div>
<a id="MyDisplayOnOff0" href="./Menu%20-%20Rivers%20of%20Mind%20and%20Heart.html">Rivers of Mind and Heart</a> 
<br/>
<a id="MyDisplayOnOff1" href="./Menu%20-%20Of%20Lila%20and%20the%20Void.html">Of Lila and the Void</a> 
    </div>

</body>
</html>
链接到相同内容的zMenuB.html几乎相同,简化如下:

<!doctype html>
<html>
<head>
<title>zMenuA.html [Acknowledgement @Andu Andrici]</title>
</head>
<body>

<a href="./zSameTarget.html?redictedFrom=zMenuA">zMenuA.html invoking zSameTarget.html</a>

</body>
</html>
<!doctype html>
<html>
<head>
<title>zMenuB.html [Acknowledgement @Andu Andrici]</title>
</head>
<body>

<a href="./zSameTarget.html?redictedFrom=zMenuB">zMenuB.html invoking zSameTarget.html</a>

</body>
</html>
<!doctype html>
<html>
<head>
<title>zSameTarget.html [Acknowledgement @Andu Andrici]</title>
<style></style>

<script type="text/javascript">
    var MyAppendedUrlMarker = window.location.search

    if (MyAppendedUrlMarker === '?redictedFrom=zMenuA') {
    onload = function () {
    document.head.insertAdjacentHTML('beforeend', "<link href='addOtherCSSstyling.css' type='text/css' rel='stylesheet'/>");

        var MyElement = 
document.getElementById("MyDisplayOnOff0").style.display = "inline";
        var MyElement = 
document.getElementById("MyDisplayOnOff1").style.display = "none";
        }
    }

    if (MyAppendedUrlMarker === '?redictedFrom=zMenuB') { 
    onload = function () {
        var MyElement = 
document.getElementById("MyDisplayOnOff0").style.display = "none";
        var MyElement = 
document.getElementById("MyDisplayOnOff1").style.display = "inline";
        }        
    }
</script>

</head>

<body>

<p style="white-space:pre-wrap;">
This is the child page 'zSameTarget.html' with this content showing 
the same; BUT, at the bottom, with different content [a navigation link] 
being visible and active, solely dictated by which parent page invoked 
this page. To whit, whether in opening this page, an [a href ....] was 
clicked on 'zMenuA.html', or if it came from a click originating from 
'zMenuB.html' instead. NOTE: running this page alone will show two links. 
It is meant to show only one link. Therefore, first open 'zMenuA.html' 
or 'zMenuB.html' and then link to this page from either one of them. As
indicated, depending on the page chosen, one will find it has produced a 
different content [link in this case] visible at the bottom. As well, I 
have added a linked 'myFile.css' to modify the styling elsewhere when
'zMenuA.html' is identified as the parent in the 'if' statements.</p><br/>

    <div>
<a id="MyDisplayOnOff0" href="./Menu%20-%20Rivers%20of%20Mind%20and%20Heart.html">Rivers of Mind and Heart</a> 
<br/>
<a id="MyDisplayOnOff1" href="./Menu%20-%20Of%20Lila%20and%20the%20Void.html">Of Lila and the Void</a> 
    </div>

</body>
</html>
“zSameTarget.html”是一个内容页面,其“开/关-或者”导航链接通过评估哪个页面是其父页面来设置,简化如下:

<!doctype html>
<html>
<head>
<title>zMenuA.html [Acknowledgement @Andu Andrici]</title>
</head>
<body>

<a href="./zSameTarget.html?redictedFrom=zMenuA">zMenuA.html invoking zSameTarget.html</a>

</body>
</html>
<!doctype html>
<html>
<head>
<title>zMenuB.html [Acknowledgement @Andu Andrici]</title>
</head>
<body>

<a href="./zSameTarget.html?redictedFrom=zMenuB">zMenuB.html invoking zSameTarget.html</a>

</body>
</html>
<!doctype html>
<html>
<head>
<title>zSameTarget.html [Acknowledgement @Andu Andrici]</title>
<style></style>

<script type="text/javascript">
    var MyAppendedUrlMarker = window.location.search

    if (MyAppendedUrlMarker === '?redictedFrom=zMenuA') {
    onload = function () {
    document.head.insertAdjacentHTML('beforeend', "<link href='addOtherCSSstyling.css' type='text/css' rel='stylesheet'/>");

        var MyElement = 
document.getElementById("MyDisplayOnOff0").style.display = "inline";
        var MyElement = 
document.getElementById("MyDisplayOnOff1").style.display = "none";
        }
    }

    if (MyAppendedUrlMarker === '?redictedFrom=zMenuB') { 
    onload = function () {
        var MyElement = 
document.getElementById("MyDisplayOnOff0").style.display = "none";
        var MyElement = 
document.getElementById("MyDisplayOnOff1").style.display = "inline";
        }        
    }
</script>

</head>

<body>

<p style="white-space:pre-wrap;">
This is the child page 'zSameTarget.html' with this content showing 
the same; BUT, at the bottom, with different content [a navigation link] 
being visible and active, solely dictated by which parent page invoked 
this page. To whit, whether in opening this page, an [a href ....] was 
clicked on 'zMenuA.html', or if it came from a click originating from 
'zMenuB.html' instead. NOTE: running this page alone will show two links. 
It is meant to show only one link. Therefore, first open 'zMenuA.html' 
or 'zMenuB.html' and then link to this page from either one of them. As
indicated, depending on the page chosen, one will find it has produced a 
different content [link in this case] visible at the bottom. As well, I 
have added a linked 'myFile.css' to modify the styling elsewhere when
'zMenuA.html' is identified as the parent in the 'if' statements.</p><br/>

    <div>
<a id="MyDisplayOnOff0" href="./Menu%20-%20Rivers%20of%20Mind%20and%20Heart.html">Rivers of Mind and Heart</a> 
<br/>
<a id="MyDisplayOnOff1" href="./Menu%20-%20Of%20Lila%20and%20the%20Void.html">Of Lila and the Void</a> 
    </div>

</body>
</html>

我正在努力理解被问到的问题。我通常也不会访问源网站,因为1.链接会消失,2.如果是恶意的怎么办?3.这通常会让问题变得更加混乱。你愿意至少用HTML构建一个代码段吗?谢谢@StealthtenInja。如果我不清楚,我很抱歉。我确实在javascript中添加了一个必需的代码段为了清晰起见,在第一次发布后。我使用的html内容是一首诗,然后在页面底部,本地路径href是这样的…您想根据页面的URL显示或隐藏元素吗?CodeF0x,谢谢。是的,如果理解为URL引用ed to是点击链接后生成新内容页旅程的页面的URL。新内容页是我们希望对该URL进行加载查询并隐藏或显示所需元素[链接]取决于是URL-a还是URL-b。谢谢@Andu Andrici,在新的一天里,我会努力跟上进度,融入你的思想和知识。我非常感谢你的投入。很高兴它有所帮助。
如果成功了,请告诉我。祝你好运!谢谢@Andu Andrici我已经使用了您出色的代码,将您的查询字符串?redictedFrom=zpage1返回到第2页的警报框中。在继续之前,请注意,在我的情况下,由于许多原因(包括六个被简化为page1的菜单页面),功能上最简单的是在加载时使用page1,而不是在page1上重新编码单独必需的HREF,只需将?redictedFrom=zpage1添加到任何内容Kudos@Andu Andrici即可。从您提供的代码开始,我已经在我的工作和情境相关的最终答案中发布了。向前调整,是否可以将启动页面附加到现在单独使用href编码的“查询参数”,而不是将页面上单击的任何href指向全局附加页面的“查询参数”。在我的情况下,更好的做法是规定“查询参数”附加适用于某个[nav tag]部分或特定的[article tag Specified section],例如[article tag Specified]?