doug007 Posted August 25, 2009 Share Posted August 25, 2009 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 # Quote Link to comment Share on other sites More sharing options...
Adam Posted August 25, 2009 Share Posted August 25, 2009 You're looking for 'location.hash' I think. Quote Link to comment Share on other sites More sharing options...
doug007 Posted August 25, 2009 Author Share Posted August 25, 2009 You're looking for 'location.hash' I think. sorry that was a typo on my part, thanks though. please anyone else out there who's done something like this before? Quote Link to comment Share on other sites More sharing options...
Adam Posted August 25, 2009 Share Posted August 25, 2009 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)). Quote Link to comment Share on other sites More sharing options...
doug007 Posted August 25, 2009 Author Share Posted August 25, 2009 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? Quote Link to comment Share on other sites More sharing options...
Adam Posted August 25, 2009 Share Posted August 25, 2009 Err, so the pop up.. pops up, and you want to get the URL of that, or the parent window? And from within which window? Quote Link to comment Share on other sites More sharing options...
trq Posted August 25, 2009 Share Posted August 25, 2009 This is something I found in my bookmarks, not sure Ive even used it. http://www.netlobo.com/url_query_string_javascript.html Quote Link to comment Share on other sites More sharing options...
watsmyname Posted August 25, 2009 Share Posted August 25, 2009 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 # split a url by "#" and get the array of index 1 Quote Link to comment Share on other sites More sharing options...
doug007 Posted August 25, 2009 Author Share Posted August 25, 2009 Err, so the pop up.. pops up, and you want to get the URL of that, or the parent window? And from within which window? the popup pops up and i the url of the parent window changes from: http://wtgforum-internal/index.php?action=calendar# to http://wtgforum-internal/index.php?action=calendar#222222 so i wan to grab the latter Quote Link to comment Share on other sites More sharing options...
doug007 Posted August 25, 2009 Author Share Posted August 25, 2009 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 # split a url by "#" and get the array of index 1 how do i do this? Quote Link to comment Share on other sites More sharing options...
watsmyname Posted August 25, 2009 Share Posted August 25, 2009 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 # 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 Quote Link to comment Share on other sites More sharing options...
Adam Posted August 25, 2009 Share Posted August 25, 2009 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. Quote Link to comment Share on other sites More sharing options...
doug007 Posted August 25, 2009 Author Share Posted August 25, 2009 this is taken soo much hair of my head....but yeah lets see if someone here has come across something similar... cheers guys Quote Link to comment Share on other sites More sharing options...
watsmyname Posted August 25, 2009 Share Posted August 25, 2009 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> Quote Link to comment Share on other sites More sharing options...
doug007 Posted August 25, 2009 Author Share Posted August 25, 2009 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); } Quote Link to comment Share on other sites More sharing options...
watsmyname Posted August 25, 2009 Share Posted August 25, 2009 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 Quote Link to comment Share on other sites More sharing options...
doug007 Posted August 26, 2009 Author Share Posted August 26, 2009 thanks, the problem appears to be that the url is not sent over to the popup. so how would i go about sending the url to the popup, how can i modify the js. sadly i am not js guru....any help would really appriciated. thanks Quote Link to comment Share on other sites More sharing options...
Adam Posted August 26, 2009 Share Posted August 26, 2009 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? Quote Link to comment Share on other sites More sharing options...
doug007 Posted August 26, 2009 Author Share Posted August 26, 2009 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> Quote Link to comment Share on other sites More sharing options...
doug007 Posted August 26, 2009 Author Share Posted August 26, 2009 here is live demo: http://www.pat-burt.com/csspopup.html# Quote Link to comment Share on other sites More sharing options...
Adam Posted August 26, 2009 Share Posted August 26, 2009 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. Quote Link to comment Share on other sites More sharing options...
doug007 Posted August 26, 2009 Author Share Posted August 26, 2009 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 # Quote Link to comment Share on other sites More sharing options...
Adam Posted August 26, 2009 Share Posted August 26, 2009 Pardon? Don't follow... Quote Link to comment Share on other sites More sharing options...
doug007 Posted August 26, 2009 Author Share Posted August 26, 2009 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? Quote Link to comment Share on other sites More sharing options...
Adam Posted August 26, 2009 Share Posted August 26, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.