/    Sign up×
Community /Pin to ProfileBookmark

How to find out url of current page

Hi all,

I wonder if I can use in my javascript something like this:

if(currentURL==’http://forums.webdeveloper.com/newthread.php?action=newthread&forumid=3‘){

don’t do something

}

Actually, I need to use it without parameters, I need to avoid them, so just

if
(currentURL==http://forums.webdeveloper.com/newthread.php
‘){
don’t do something

}

Thank you for any help.

Mike

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@khalidali63Feb 05.2003 — var currentURL=document.location.href;

the above line will get the current loaded page's URL

then you can do this

if(currentURL.indexOf("http://forums.webdeveloper.com/newthread.php ")>-1){

//do or not do anything here

}

cheers

Khalid
Copy linkTweet thisAlerts:
@karibaauthorFeb 05.2003 — Thank you for your reply.

I ran into a problem, I have this javascript on a page, and I need to find out URL of a iframe, that on this page.

Is it still possible to do this?

thanks again,

Mike
Copy linkTweet thisAlerts:
@CharlesFeb 05.2003 — [font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Example</title>

<script type="text/javascript">

<!--

onload = function () {alert(document.iframe.location.href)}

// -->

</script>

<iframe src="http://www.w3c.org/" name="iframe"></iframe>

[/font][font=georgia]

Except that it will not work unless the two documents are from the same domain - for security reasons.

By the way, [font=monospace]document.location.href[/font] is problematic. In JavaScript 1.0 [font=monospace]document.location[/font] was was simply a string. In JavaScript 1.1 it was depricated in favour of the object [font=monospace]window.location[/font], [font=monospace]window.location.href[/font] being one of the properties of that object. Now to keep older web pages running, JavaScript 1.1 made [font=monospace]document.location[/font] a synonym of the object [font=monospace]window.location[/font]. This works because all objects in JavaScript have a [font=monospace]toString()[/font] method that is called when you want the object to be a string and because [font=monospace]window.location[/font] has the unique property that you can assign a string to it. All this is to say that [font=monospace]document.location.href[/font] sends a chill down the spine of JavaScript pedants and, more importantly, will not work on JavaScript 1.0 browsers. It is also possible that future browsers will no longer support [font=monospace]document.location[/font].[/font]
×

Success!

Help @kariba spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...