2014-01-06 52 views
0

我在JavaScript中並不是很聰明,所以我該如何添加到「w.location.href」?中。我試圖尋找,但很難制定正確的問題。如何在JavaScript中添加URL結尾爲「w.location.href」?

這是Chrome中的書籤的一部分:

encodeURIComponent(w.location.href) 

這將返回有效的網址在broswer ADRESS領域,如http://www.domain.com。但是我怎樣才能加入它,所以結局會像「http://www.domain.com/?rcode=abc1234」?

我嘗試這樣做:

encodeURIComponent(w.location.href + "?rcode=abc12345") 

encodeURIComponent(w.location.href + ('?rcode=abc12345') 

但沒有什麼workes,OR,它droppes了 「=」,在添加字符串。

-

好吧,我在這裏添加編輯的 「flipit」 代碼:

javascript:void((function(d,w,p,s,r,t,l)%7Bt%3D(w.screenTop%7C%7Cw.screenY)%2B50%3Bl%3D(w.screenX%7C%7Cw.screenLeft)%2B(w.innerWidth%7C%7Cd.documentElement.offsetWidth%7C%7C0)/2-s/2%3Bw.__flipboard%3Dw.open(%27https://share.flipboard.com/bookmarklet/popout%3Fv%3D2%26title%3D%27%2BencodeURIComponent(d.title)%2B%27%26url%3D%27%2BencodeURIComponent(w.location.href + "?rcode=wlb535")%2B%27%26t%3D%27%2Bp,%27__flipboard_flipit%27,%27width%3D%27%2Bs%2B%27,height%3D%27%2Br%2B%27,top%3D%27%2Bt%2B%27,left%3D%27%2Bl%2B%27,location%3Dyes,resizable%3Dyes,status%3Dno,scrollbars%3Dno,personalbar%3Dno,toolbar%3Dno,menubar%3Dno%27)%3Bs%3Dd.createElement(%27script%27)%3Bs.setAttribute(%27type%27,%27text/javascript%27)%3Bs.setAttribute(%27src%27,%27https://d2jsycj2ly2vqh.cloudfront.net/bookmarklet/js/popout-helper.min.js%3Ft%3D%27%2Bp)%3Bd.body.appendChild(s)%3BsetTimeout(function()%7Bw.__flipboard.focus()%7D,50)%3B%7D)(document,window,(new Date().getTime()),535,565)) 
+0

不應該是'窗'嗎? –

+0

它與[google-chrome-extension]有什麼關係? – gkalpak

+0

w.location被使用,我想它會是一樣的。 – Johnny

回答

0

試試這個:

var url = window.location; 
url = encodeURI(url + '?rcode=abc12345'); 
0

如果你想以編程方式更改的位置,使用:

window.location.href += encodeURIComponent('?rcode=abc12345'); 
+0

我無法通過此更改進行此項工作...查看我添加的upove代碼。但是,謝謝:) – Johnny

相關問題