2012-02-22 126 views
0

嗯,問題也許不正確,但我給了一個拍攝。javascript通過url傳遞變量

我的腳本:

<a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u);void(o)" onclick="return false">OMG, testing</a> 

在現實,沒有JavaScript網址看起來像:

http://localhost/url=google.com 

在這裏想補充一點:&格式= TXT

所以,正確的url然後將是:

http://localhost/url=google.com&format=txt 
  • 如何&格式添加到這表明在 頂部的JavaScript「腳本」?

回答

0

這樣的:

<a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u + '&format=txt');void(o)" onclick="return false">OMG, testing</a> 

你只需要在文本添加到您的網址

1

的字符串,這是你想要的東西:

<a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u+'&format=txt');void(o)" onclick="return false">OMG, testing</a> 
1

只需將它添加到鏈接使用+,除非我誤解了這個問題。

<a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u+'&format='+txt);void(o)" onclick="return false">OMG, testing</a> 

假定txt是一個變量,否則將它全部放在引號中。

1

這將做到這一點,,你必須做的一樣你爲本地主機

<a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u+'&format='+txt);void(o)" onclick="return false">OMG, testing</a>