Jump to content

Grab url


doug007

Recommended Posts

Hi Guys,

 

I am desperatly seeking a solution to how I can grab the anything after # sign on a url.

 

so given this url:

http://wtgforum-internal/index.php?action=calendar#222222

 

i want to grab everything after the # sign and input that into a input fields value?

 

i have been playing aroung with windos.locationhash but this only gets me as far as the # sign.  so doing a document.write(windows.location.hash) only prints out everything upto #

 

:confused:

Link to comment
Share on other sites

Sorry, I actually missed the line where you mentioned location.hash before. This is odd. What browser are you using? Works fine for me in every browser I have (Firefox, Chrome, Safari, IE (even 6)).

 

ok i see what the problem is now.  i am opening a popup window and the url changes from initialy being

 

http://wtgforum-internal/index.php?action=calendar#

to

http://wtgforum-internal/index.php?action=calendar#222222

 

so hence why it does not grab the #222222

 

how can i fix this?

Link to comment
Share on other sites

Hi Guys,

 

I am desperatly seeking a solution to how I can grab the anything after # sign on a url.

 

so given this url:

http://wtgforum-internal/index.php?action=calendar#222222

 

i want to grab everything after the # sign and input that into a input fields value?

 

i have been playing aroung with windos.locationhash but this only gets me as far as the # sign.  so doing a document.write(windows.location.hash) only prints out everything upto #

 

:confused:

split a url by "#" and get the array of index 1

Link to comment
Share on other sites

Hi Guys,

 

I am desperatly seeking a solution to how I can grab the anything after # sign on a url.

 

so given this url:

http://wtgforum-internal/index.php?action=calendar#222222

 

i want to grab everything after the # sign and input that into a input fields value?

 

i have been playing aroung with windos.locationhash but this only gets me as far as the # sign.  so doing a document.write(windows.location.hash) only prints out everything upto #

 

:confused:

split a url by "#" and get the array of index 1

 

how do i do this?

Link to comment
Share on other sites

Hi Guys,

 

I am desperatly seeking a solution to how I can grab the anything after # sign on a url.

 

so given this url:

http://wtgforum-internal/index.php?action=calendar#222222

 

i want to grab everything after the # sign and input that into a input fields value?

 

i have been playing aroung with windos.locationhash but this only gets me as far as the # sign.  so doing a document.write(windows.location.hash) only prints out everything upto #

 

:confused:

split a url by "#" and get the array of index 1

 

how do i do this?

 

var strurl="http://wtgforum-internal/index.php?action=calendar#222222";

var splitted=strurl.split("#");

document.write splitted[1] //your value should be 222222

Link to comment
Share on other sites

var strurl="http://wtgforum-internal/index.php?action=calendar#222222";

var splitted=strurl.split("#");

document.write splitted[1] //your value should be 222222

 

Yeah but it's not a static string, it's the URL of the current page. "location.hash" exists really for this type of use.

 

Odd. I can't see why it wouldn't work, unless the location.hash property isn't updated as it's changed (which I can't really see being the case). Perhaps have a search around for known 'location.hash bugs', or perhaps someone here as some experience.

Link to comment
Share on other sites

this is taken soo much hair of my head....but yeah lets see if someone here has come across something similar...

 

cheers guys

okay here i tested and it worked

 

<script language="javascript" type="text/javascript">
var strurl=window.location.href+"";
var splitted=strurl.split("#");
alert(splitted[1]);
</script>

Link to comment
Share on other sites

this is taken soo much hair of my head....but yeah lets see if someone here has come across something similar...

 

cheers guys

okay here i tested and it worked

 

<script language="javascript" type="text/javascript">
var strurl=window.location.href+"";
var splitted=strurl.split("#");
alert(splitted[1]);
</script>

 

but it does not work on the popup window. 

 

initially the url is this:

http://wtgforum-internal/index.php?action=calendar#

 

when you click on a link to create the popup

<a href="<?=$url?>" onclick="popup('popUpDiv')"><?=$title?></a>

 

it creates a popup, then the url on the parent window chnages to this

http://wtgforum-internal/index.php?action=calendar#222222

 

and your script only prints out 'undefined' on the popup window.

 

the js the creates the popup is here

function toggle(div_id) {
var el = document.getElementById(div_id);
if ( el.style.display == 'none' ) {	el.style.display = 'block';}
else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar) {
if (typeof window.innerWidth != 'undefined') {
	viewportheight = window.innerHeight;
} else {
	viewportheight = document.documentElement.clientHeight;
}
if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
	blanket_height = viewportheight;
} else {
	if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
		blanket_height = document.body.parentNode.clientHeight;
	} else {
		blanket_height = document.body.parentNode.scrollHeight;
	}
}
var blanket = document.getElementById('blanket');
blanket.style.height = blanket_height + 'px';
var popUpDiv = document.getElementById(popUpDivVar);
popUpDiv_height=blanket_height/2-350;//150 is half popup's height
popUpDiv.style.top = popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
if (typeof window.innerWidth != 'undefined') {
	viewportwidth = window.innerHeight;
} else {
	viewportwidth = document.documentElement.clientHeight;
}
if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
	window_width = viewportwidth;
} else {
	if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
		window_width = document.body.parentNode.clientWidth;
	} else {
		window_width = document.body.parentNode.scrollWidth;
	}
}
var popUpDiv = document.getElementById(popUpDivVar);
window_width=window_width/2-150;//150 is half popup's width
popUpDiv.style.left = window_width + 'px';
}
function popup(windowname) {
blanket_size(windowname);
window_pos(windowname);
toggle('blanket');
toggle(windowname);		
}

Link to comment
Share on other sites

this is taken soo much hair of my head....but yeah lets see if someone here has come across something similar...

 

cheers guys

okay here i tested and it worked

 

<script language="javascript" type="text/javascript">
var strurl=window.location.href+"";
var splitted=strurl.split("#");
alert(splitted[1]);
</script>

 

but it does not work on the popup window. 

 

initially the url is this:

http://wtgforum-internal/index.php?action=calendar#

 

when you click on a link to create the popup

<a href="<?=$url?>" onclick="popup('popUpDiv')"><?=$title?></a>

 

it creates a popup, then the url on the parent window chnages to this

http://wtgforum-internal/index.php?action=calendar#222222

 

and your script only prints out 'undefined' on the popup window.

 

the js the creates the popup is here

function toggle(div_id) {
var el = document.getElementById(div_id);
if ( el.style.display == 'none' ) {	el.style.display = 'block';}
else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar) {
if (typeof window.innerWidth != 'undefined') {
	viewportheight = window.innerHeight;
} else {
	viewportheight = document.documentElement.clientHeight;
}
if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
	blanket_height = viewportheight;
} else {
	if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
		blanket_height = document.body.parentNode.clientHeight;
	} else {
		blanket_height = document.body.parentNode.scrollHeight;
	}
}
var blanket = document.getElementById('blanket');
blanket.style.height = blanket_height + 'px';
var popUpDiv = document.getElementById(popUpDivVar);
popUpDiv_height=blanket_height/2-350;//150 is half popup's height
popUpDiv.style.top = popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
if (typeof window.innerWidth != 'undefined') {
	viewportwidth = window.innerHeight;
} else {
	viewportwidth = document.documentElement.clientHeight;
}
if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
	window_width = viewportwidth;
} else {
	if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
		window_width = document.body.parentNode.clientWidth;
	} else {
		window_width = document.body.parentNode.scrollWidth;
	}
}
var popUpDiv = document.getElementById(popUpDivVar);
window_width=window_width/2-150;//150 is half popup's width
popUpDiv.style.left = window_width + 'px';
}
function popup(windowname) {
blanket_size(windowname);
window_pos(windowname);
toggle('blanket');
toggle(windowname);		
}

well it worked for me

first page is a.html... i have text link when clicked it calls function openme. this is what i have in a.html

<script language="javascript" type="text/javascript">
function openme(){
window.open("t.html#222222","mname");
}
</script>

t.html consist of code i posted earlier...and it worked for me. YOU NEED TO MODIFY STUFFS IN YOUR CODE

Link to comment
Share on other sites

That's no pop up *window* script, it's a JS page-based pop up - never really know what to call them. That shouldn't alter the URL at all, unless, how are you calling this pop up? I reckon they may be using the <a href="#"... trick which is removing the hash. This would be much easier if there was a live version to take a look at?

Link to comment
Share on other sites

That's no pop up *window* script, it's a JS page-based pop up - never really know what to call them. That shouldn't alter the URL at all, unless, how are you calling this pop up? I reckon they may be using the <a href="#"... trick which is removing the hash. This would be much easier if there was a live version to take a look at?

 

this is how i am calling it:

 

<a href="#" onclick="popup('popUpDiv')">popup</a>

Link to comment
Share on other sites

Ahh. It's the hash in the 'href' causing the error. For example, go to:

 

http://www.pat-burt.com/csspopup.html#test

 

Clear the address bar and enter:

 

javascript:alert(location.hash);

 

Alerts '#test'. Click to open the popup then re-enter the javascript command into the address bar, nothing is returned. You need to re-think the way you're calling the pop up. I suggest:

 

<a href="javascript:void(0);" onclick="popup('popUpDiv')">popup</a>

 

Although I would recommend looking into replacing that with a JS-disabled friendly alternative.

Link to comment
Share on other sites

Ahh. It's the hash in the 'href' causing the error. For example, go to:

 

http://www.pat-burt.com/csspopup.html#test

 

Clear the address bar and enter:

 

javascript:alert(location.hash);

 

Alerts '#test'. Click to open the popup then re-enter the javascript command into the address bar, nothing is returned. You need to re-think the way you're calling the pop up. I suggest:

 

<a href="javascript:void(0);" onclick="popup('popUpDiv')">popup</a>

 

Although I would recommend looking into replacing that with a JS-disabled friendly alternative.

 

thats cool, but I want to remain on the same window and the page does not have reload, hence why we using #

Link to comment
Share on other sites

Pardon? Don't follow...

 

sorry adam my bad.  i found a way around this problem, but this leads me to another question?  is it possible to actualy edit the a popup window so it does not show the top part of the window and the borders, so say i have form on the popup i only want that to be visiable and nothoing else?

Link to comment
Share on other sites

If I understand you right, you mean the content outside of the pop up to be completely invisible... what's currently darkened out? If so you can just edit the CSS of the "#blanket" DIV like so:

 

#blanket {
   background-color:#FFF; /* or whatever color you want it to be */
   position:absolute;
   z-index: 9001; /*ooveeerrrr nine thoussaaaannnd*/
   top:0px;
   left:0px;
   width:100%;
}

 

Note I've removed the "opacity" property.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.