opening a new window based on the current url of the page

Will

So ostensibly I'm trying to make a button or a link who's target is contingent on the current page's URL. I'm working on a Wordpress portfolio site that opens up different projects in an Ajax window, but I also want to be able to link to the separate project page from that window. For instance, if I click the thumbnail for a project titled "Blue" it opens up the project in the ajax window and the url changes to "www.website.com/#blue." Incidentally, the url of the corresponding project page would then be "www.website.com/projects/blue". The idea is to hardcode the button into the Ajax window and write a script that generates the correct URL for the project page so my client doesn't have to copy-paste the code for the button and update the target URL every time she posts a project. This is what I came up with, but I'm not great with Jquery or Javascript and I think something might be wrong with my syntax or the structure of the script. Right now, nothing happens when I press the button.

First it splits the url at each "/" and creates an array from the different strings, then it removes the "#" from the unique string, and opens a new window with the new address.

EDIT There were some syntax errors, but it's still not working. Any thoughts on this new version:

$(".comment_button").click(function(){
var parse_url = window.location.href.split('/');
var project_name = parse_url[2].replace("#", "");
window.open("http://www.balletinform.com/projects/" + project_name);
});
Kaiido

If I understand correctly, what you want to get is the #blue part of the url.

If so, you can use window.location.hash.

Your function will then looks like window.open("http://www.balletinform.com/projects/" + window.location.hash.substring(1));

Your current function was setting project_name to "www.balletinform.com" ([0]=>"http:"; splitted(/); [1]=>""; splitted('/'); [2]=>"www.balletinform.com"; splitted('/'); [3]=>"#blue").
So an alternative solution would have been var project_name = parse_url[parse_url.length-1].replace("#", "");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

opening a new window based on the current url of the page

From Dev

Open page in new tab/window AND direct current window to a new url

From Dev

link opening new window and refreshing current

From Dev

Refresh/navigate current page while opening/downloading file in new tab/window

From Dev

Opening an old page from new url

From Dev

why is window.open(url) opening new window instead of tab

From Dev

Is there a way to keep current window active when opening a new program?

From Dev

Force button to reload page after opening new window

From Dev

object contents lost when opening new page within window

From Dev

page opening in both window

From Dev

Window not opening in a new tab

From Dev

opening a link in a new window

From Dev

Opening new window in wicket

From Dev

Opening New Window in Jframe

From Dev

Opening the URL in a new window in SSRS while passing a paramater

From Dev

Current URL parameter in a new link in the page

From Dev

Edge and opening a new page

From Dev

opening window and navigating through page

From Dev

Opening a new terminal window in C

From Dev

Opening new window from ViewModel

From Dev

HTML "mailto:" not opening in new window

From Dev

Opening new window with button in OpenERP

From Dev

Click on link not opening in new window

From Dev

opening new window in PHP not working

From Dev

GUI, JComboBox and opening a new window

From Dev

Opening an SWF file in a new window

From Dev

Open particular Jquery accordion pan based on current page URL

From Dev

Struts2 jsp page opening in a new window instead of content div

From Dev

Tweet button opening new window and new tab

Related Related

HotTag

Archive