Jump to content

Reading complete url


Darghon

Recommended Posts

Hello all

 

I have a page that has multiple tab pages, the tabs can be opened by clicking on them, and it all works via javascript.

I changed the tab clicking code to append the address bar with #tabname

So a user can choose a tab and the address bar will change without the page refreshing.

Now when a user presses refresh, I'd like to read the # value so I know what tab I need to put open.

Is this possible with PHP, or does it have to be done with JavaScript, if so let me know and I'll move this topic to the JavaScript part.

 

So I want to be able to get the following from the example link:

http://Localhost/Website/Realm.php?c=Town&b=1#info

c = Town

b = 1

# = info

so that I can select info as the opened tab

 

Thx in advance

Link to comment
Share on other sites

I've been trying to get it to work, but this is how my setup is

 

in the webpage I have 1 include that contains the entire websites javascript code.

so in there I made a function like this =>

document.onload = function setTab(){
	alert("trigger");
	var url = window.location.href;
	var anch = url.substr(url.indexOf('#')+1);
	alert(anch);
	if(anch != ""){  
		toggleTab(document.getElementById('tabheader'),document.getElementById('tabcontent'), anch);
		alert(anch);
	}
}

 

the toggleTab function works, but it won't load this function on a onload event

The javascript page is imported at the top of the page (and must stay there)

Link to comment
Share on other sites

changed the function to

window.onLoad = function setTab(){
	var url = window.location.href;
	var anch = url.substr(url.indexOf('#')+1);
	if(anch != ""){  
		toggleTab(document.getElementById('tabheader'),document.getElementById('tabcontent'), anch);
	}
}

And it works great now.

Thx :)

Link to comment
Share on other sites

changed the function to

window.onLoad = function setTab(){
	var url = window.location.href;
	var anch = url.substr(url.indexOf('#')+1);
	if(anch != ""){  
		toggleTab(document.getElementById('tabheader'),document.getElementById('tabcontent'), anch);
	}
}

And it works great now.

thanks :)

 

First sorry for triple post, but can't edit my previous...

 

the code won't work like that, the error with it is, if no # is found in the address line, then it'll use the complete address line instead of nothing.

 

To fix this I changed the function to =>

window.onload = function(){
	var url = window.location.href;
	if(url.indexOf('#') != -1){  
		toggleTab(document.getElementById('tabheader'),document.getElementById('tabcontent'), url.substr(url.indexOf('#')+1));
	}
}

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.