我们如何将当前页面的名称变为变量? [英] How do we get the name of the present page into a varible?

查看:77
本文介绍了我们如何将当前页面的名称变为变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI!如何将当前页面的名称变为变量?我需要它

因为我需要将它附加到路径上,所以我可以让别人链接到我。

我的页面在iframe中。


Paul

解决方案

paul于2006年2月25日在comp.lang.javascript中写道

HI!如何将当前页面的名称变为变量?我需要它
因为我需要将它附加到路径上以便我可以让其他人链接到我。
我的页面在iframe中。




var pathAndPage = location.href

-

Evertjan。

荷兰。

(请更改x''es到我的电子邮件地址中的点数)


问候,


如果你只是想要,你也可以使用以下内容你在的页面

没有网址的其余部分。


< script>

var thisPath = window.location。 pathname;

var thisPage = thisPath.substring(thisPath.lastIndexOf(''/'')+ 1); //

当前页

< / script>


您只需使用可变的thisPage即可。获得当前页面你

开启。


希望这会有所帮助,


- Peter Schmalfeldt

Manifest Interactive


HI!谢谢你的回复,我想虽然我可能需要修剪它。我ñ
看到它给了我整条路径而不只是页面名称。所以我要

创建一个IF语句来检查一个条件是否为真然后删除

这个我不想要的部分。我将不得不重新发布,因为这与

这个标题不同。


Paul


" Evertjan。 " <前************** @ interxnl.net>在消息中写道

news:Xn ******************** @ 194.109.133.242 ...

paul 2006年2月25日在comp.lang.javascript中写道

HI!如何将当前页面的名称变为变量?我需要它
因为我需要将它附加到路径上以便我可以让其他人链接到我。
我的页面在iframe中。



var pathAndPage = location.href

-
Evertjan。
荷兰。
(请将我的电子邮件地址中的x'变为点数)



HI! How so get the name of the present page into a variable? I need it
because I need to attach it to a path so I can make others link to me.
My pages are in iframes.

Paul

解决方案

paul wrote on 25 feb 2006 in comp.lang.javascript:

HI! How so get the name of the present page into a variable? I need it
because I need to attach it to a path so I can make others link to me.
My pages are in iframes.



var pathAndPage = location.href
--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)


Greetings,

You can also use the following if you just want the page you are on
WITHOUT the rest of the URL.

<script>
var thisPath = window.location.pathname;
var thisPage = thisPath.substring(thisPath.lastIndexOf(''/'') + 1); //
current page
</script>

You would just use the vaiable "thisPage" to get the current page you
are on.

Hope this helps,

- Peter Schmalfeldt
Manifest Interactive


HI! Thanks for the reply, I think though I might need to trim it though. I
see that it give me the whole path and not just page name. so I have to
create a IF statement to check to see if a condition is true then trim out
the part that I don''t want. I will have to repost as this is different than
this heading.

Paul

"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.242...

paul wrote on 25 feb 2006 in comp.lang.javascript:

HI! How so get the name of the present page into a variable? I need it
because I need to attach it to a path so I can make others link to me.
My pages are in iframes.



var pathAndPage = location.href
--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)



这篇关于我们如何将当前页面的名称变为变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆