2016-03-21 14 views
-1

"Mağaza kimliğinizi girin" etiketli bir Metin kutusu ve bir submit düğmesi ile bir HTML formu oluşturmaya çalışıyorum. Daha sonra submit düğmesine basıldığında, alt alanın girilen ile farklı bir web sitesine yeniden yönlendirilmesini istiyorum.Gönderilen form URL'ye girmek için yönlendirin

Örnekler:
"12345" girilirse , onlar yönlendirilmek için 12345.myothersite.com "987654" girilirse, onlar bu jQuery etiketlediğinizden beri iyi misin tahmin 987654.myothersite.com

+0

deneyin t Onun konu, http://stackoverflow.com/questions/1167068/apache-mod-rewrite-a-subdomain-to-a-subfolder-via-internal-redirect. – chris85

cevap

1

yönlendirildi olsun
jQuery cevabı ile.

HTML:

<form id="form"> 
    <input id="subdomain"/> 
    <input type="submit"/> 
</form> 

JavaScript:

$(document).ready(function() { 
    $("#form").submit(function(event) { 
    event.preventDefault(); 
    window.location.href = "http://" + $("#subdomain").val() + ".somesite.com/" 
    }); 
}); 
+0

'window.location = ...' bazı tarayıcılarda çalışmaz, 'window.location.href = ...' çoğu tarayıcı ile uyumludur –

+0

Herhangi bir modern tarayıcıda görmedim, ama haklısınız Bazı eski tarayıcıları bozabilir. Cevabımı güncelleyeceğim. – Chris

0
window.location.href = document.getElementById('inputBox').value + '.myothersite.com'; 

Örnek:

https://jsfiddle.net/53q2jf2k/

<form onsubmit="return false"> 
    <input type="text" id="inputBox"/> 
    <button onclick="changeURL()" >Submit</button> 
</form> 


function changeURL() { 
    window.location.href = document.getElementById('inputBox').value + '.myothersite.com'; 

    alert(document.getElementById('inputBox').value + '.myothersite.com') 
} 
İlgili konular