2017-08-09 64 views
1

而且我的代碼如下所示,當郵箱打開時,它在JS代碼段中斷。如何在mailto正文文本中追加Java腳本代碼

<a href="mailto:?subject=This is My Subject&body=Hithis is my text and my page url is"+window.location.href+\" click link to see Greater experienceto" target="_top" class=""> 

Email

在哪裏,我希望它能夠動態顯示的網址,其中鏈接在頁面可用。 Expected email

+0

打破如何?您的控制檯或記錄器有錯誤嗎? 'window.href'是否必須被轉義,因爲它包含了不屬於URL的東西? – jdv

+0

@jdv剛剛更新了問題。我期待的動態網頁鏈接輸出爲'Hithis是我的文本,我的網頁地址是**(h ttp://mydomain.com/mypage)**點擊鏈接查看更多的體驗到' –

+0

在任何地方使用調試器瀏覽器檢查'window.location.href'來查看它的設置。順便說一句,我認爲這個問題是重複的:https://stackoverflow.com/q/17863986/1531971 – jdv

回答

0

試試這樣說:

<a href="#" onclick="javascript:window.location='mailto:?subject=Interesting information&body=I thought you might find this information interesting: ' + window.location + ' click link to see Greater experienceto'">Click</a> 
0


您的瀏覽器可能不支持可能。你有沒有嘗試更新你的瀏覽器或重新安裝?當你實現inbuild函數時,跨瀏覽器測試總會遇到問題。 爲我自己。我會一直建立自己的形式來避免這種情況。其長期的理念,但總是最安全的,並將在未來節省更多的時間。 創建您自己的郵件形式的例子... ..`dds

<form action="mailto:[email protected]" method="post" enctype="text/plain"> 
Name:<br> 
<input type="text" name="name"><br> 
E-mail:<br> 
<input type="text" name="mail"><br> 
Mail:<br> 
<input type="text" name="email" style="width:600px; height: 100px"><br><br> 
<input type="submit" value="Send"> 
<input type="reset" value="Reset"> 
</form> 

`

試試這個。 我希望這會有所幫助.. 如果你想和上面發佈的完全一樣。你只需要做一些造型。我會推薦的是添加一個div並將其包裝在其中。所以例如。

<div id="main-container"> 
    <form>.. 
    .. 
    .. 
    .. 
    </form> 
</div> 

乾杯。 :)