最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

url rewriting - URL masking in JavaScript - Stack Overflow

programmeradmin4浏览0评论

I currently have the following JavaScript function that will take current URL and concatenate it to another site URL to route it to the appropriate feedback group:

function sendFeedback() {
    url = window.location.href;
    newwin = window.open('/?s=' + url, 'Feedback');
}

Not sure if this is the proper terminology, but I want to mask the URL in the window.open statement to use the URL from the current window.

How would I be able to mask the window.open URL with the original in JavaScript?

I currently have the following JavaScript function that will take current URL and concatenate it to another site URL to route it to the appropriate feedback group:

function sendFeedback() {
    url = window.location.href;
    newwin = window.open('http://www.anothersite./home/feedback/?s=' + url, 'Feedback');
}

Not sure if this is the proper terminology, but I want to mask the URL in the window.open statement to use the URL from the current window.

How would I be able to mask the window.open URL with the original in JavaScript?

Share Improve this question asked Oct 18, 2010 at 22:58 Michael KniskernMichael Kniskern 25.3k70 gold badges169 silver badges233 bronze badges 2
  • @Assaf - Instead of displaying "anothersite./home/feedback/?s=www.mysite." in the new browser address bar, I want to display "www.mysite.". – Michael Kniskern Commented Oct 18, 2010 at 23:08
  • 1 From what I understand, you cannot manipulate the address bar of the browser window. – Šime Vidas Commented Oct 18, 2010 at 23:23
Add a ment  | 

2 Answers 2

Reset to default 4

Things you could do:

1- Mask the external site in a html frame inside a document from your site. (for example www.mysite./shortUrl/)

2-Send a Location HTTP header (real url will eventually be displayed)

Keep in mind that browsers do their best to show the real address due to phishing concerns.

I wouldn't use javascript if I wanted to mask url even thought it would work with javascript. You wouldn't get much benefits in that scenario.

The reason is simple:

  • javascript/jQuery = functions belongs to client-side (browswer/your PC/DOM)

  • links, url, http, and headers = functions belongs to Apache.

Apache is always top level above client-side. Whenever link is fired to SampeLink.html, Apache wakes up and reads the file, but links/urls are already owned before javascript could claim them. So, it is kinda of pointless if you tried to manipulate links in your javascript scripts, even though it works but weak.

I'd point you to this awesome approach: .htaccess and you will be surprised how powerful it is. If .htaccess is presented in the parent folder of SampleLink.html, Apache denies the DOM engine (your browser) from reading files until Apache have finished reading .htaccess.

With your scenario, .htaccess can do some work for you by rewriting links and send "decoy" links to the DOM engine, meanwhile keeping the orginial links/urls behind the curtain; and visitors would reach to 404page if they tried to break the app or whatever you are concerned about.

This is a bit plicated, but it never ceased to fail me. I use this as my "bible" http://corz/serv/tricks/htaccess2.php.

发布评论

评论列表(0)

  1. 暂无评论