如何用JS得到当前页面的URL信息

如何用JS得到当前页面的URL信息,第1张

设置或获取对象指定的文件名或路径。

<script>

alert(windowlocationpathname)

</script>

设置或获取整个 URL 为字符串。

<script>

alert(windowlocationhref);

</script>

设置或获取与 URL 关联的端口号码。

<script>

alert(windowlocationport)

</script>

设置或获取 URL 的协议部分。

<script>

alert(windowlocationprotocol)

</script>

设置或获取 href 属性中在井号“#”后面的分段。

<script>

alert(windowlocationhash)

</script>

设置或获取 location 或 URL 的 hostname 和 port 号码。

<script>

alert(windowlocationhost)

</script>

设置或获取 href 属性中跟在问号后面的部分。

<script>

alert(windowlocationsearch)

</script>

<script type="text/javascript">

onload = function ()

{

    var locurl = windowlocationhost; //获取当前页主域名

    var tiaozhuan = documentgetElementById("tiaozhuan");

    if(locurl == 'C')

    {

        tiaozhuansrc='D';

    }

    else

    {

        tiaozhuansrc='B';

    }

}

</script>

<iframe id="tiaozhuan" src="B" scrolling="no" frameborder="0" marginwidth="0px" marginheight="0px"></iframe>

用ajax。

引入jquery的话

$("button")click(function(){

$("div")load('testhtml');

});

如果你要获取这个页面某个id或者类的html还可以这么写

$("button")click(function(){

$("div")load('testhtml

#container');

});

这个可以直接把新页面的html元素加载到指定的div或者别的元素里面。

如果你要纯代码的话,那再获取这个div的html就可以了。

$("div")html();

<script language="JavaScript">

{

documentwrite(documenttitle)

}

</script>

这个是用JS实现的调用当前页面title的 jquery同理。关于调用地址 你已经会了

以上就是关于如何用JS得到当前页面的URL信息全部的内容,包括:如何用JS得到当前页面的URL信息、怎么用js获取当前页的主域名后改变iframe的src地址、怎么用JS获取某一个指定页面(非本页面)的HTML代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/9594999.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-30
下一篇 2023-04-30

发表评论

登录后才能评论

评论列表(0条)

保存