1 回答

TA貢獻1807條經驗 獲得超9個贊
您可以使用 javascript 嘗試類似的操作:
<html>
<head>
<title>Web Client</title>
</head>
<style>
body {
margin: 0;
padding: 0;
}
body, iframe {
width: 100%;
height: 100%;
}
iframe {
border: 0;
}
</style>
<body>
<iframe id="website" src=""></iframe>
</body>
<script type="text/javascript">
//Get the current URL
var currentURL = window.location.href;
//Get the subdomain from URL
var hostnameURL = currentURL.replace(/(http[s]*\:\/\/)/gi, '').split("/")[0];
//Set the page title
document.title = hostnameURL;
//Transform subdomain to alphaNumeric
var alphaNumericSubDomainName = hostnameURL.replace(/[^\w]/gi, '');
//Set the subdomain to the iframe (don't forget to change the domain name below)
document.getElementById("website").src = "https://"+ alphaNumericSubDomainName + ".domain.tld";
</script>
</html>
我首先獲取當前的 URL。然后我獲取 URL 的主機名(不帶 TLD 的域)。
我使用這個主機名來設置標題。然后我刪除主機名中的特殊字符并將此清理后的主機名連接為子域。
最后,我將這個新 URL 作為 Iframe 的源 URL。
- 1 回答
- 0 關注
- 182 瀏覽
添加回答
舉報