0

Found a broken link on the company site today, after some digging, here's what I found: a simple JS function to open an FAQ.aspx page within a master HTML page's site navigation.

function openFAQ() {
        window.open(location.protocol + "help/FAQ.aspx", "null", "width=750, height=800, resizable=1, scrollbars=1, location=0, directories=0, status=no, menubar=no, toolbar=no");
}

The site is dynamically pieced together. From the main page (primary web app)

http://example.com/index.aspx

the link to the FAQ works -- With the correct URL being

http://example.com/help/FAQ.aspx

If I navigate to

http://example.com/userpages/settings.aspx

the menu is still available, but when FAQ is clicked, it generates the following URL:

http://example.com/userpages/help/FAQ.aspx.

Putting "~/help/FAQ.aspx" doesn't work as it does for src or href. Not sure how to get this working. Thanks in advance

2 Answers 2

2

window.open("/help/FAQ.aspx"....) should do the trick

Sign up to request clarification or add additional context in comments.

2 Comments

haha, wow, thank you. Just curious, is / javascript's way of denoting the root? And is ~/ more a html/terminal thing?
Good question. Its a root-relative url and I believe it's actually in the HTML specification and not JavaScript, although I didn't look. For example, you could do <a href="/home/FAQ.aspx">Help Link</a> in HTML and it would work the same way. ~ is ASP.Net server-side thing and denotes folder on the file system where the application is running.
1

I guess this should work,

 function openFAQ() {
            window.open(window.location.hostname+ "/help/FAQ.aspx", "null", "width=750, height=800, resizable=1, scrollbars=1, location=0, directories=0, status=no, menubar=no, toolbar=no");
    }

location.protocol  provides the protocol used, e.g., http:, https: etc
location.hostname provides the hostname, e.g., www.mysite.com

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.