Click to See Complete Forum and Search --> : How to find out url of current page
kariba
02-04-2003, 07:58 PM
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
khalidali63
02-04-2003, 08:03 PM
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
kariba
02-04-2003, 09:13 PM
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
Charles
02-04-2003, 09:39 PM
<!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>
Except that it will not work unless the two documents are from the same domain - for security reasons.
By the way, document.location.href is problematic. In JavaScript 1.0 document.location was was simply a string. In JavaScript 1.1 it was depricated in favour of the object window.location, window.location.href being one of the properties of that object. Now to keep older web pages running, JavaScript 1.1 made document.location a synonym of the object window.location. This works because all objects in JavaScript have a toString() method that is called when you want the object to be a string and because window.location has the unique property that you can assign a string to it. All this is to say that document.location.href 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 document.location.